Skip to content

Commit

Permalink
Merge pull request #1340 from fluidvanadium/fewer_boxes
Browse files Browse the repository at this point in the history
Fewer boxes
  • Loading branch information
Oscar-Pepper authored Aug 28, 2024
2 parents a0ccae4 + db6dba0 commit 7666df9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 2 additions & 0 deletions libtonode-tests/tests/concrete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ mod fast {

let value_transfers = &recipient.value_transfers().await;

dbg!(value_transfers);

assert!(value_transfers
.iter()
.any(|vt| vt.kind() == ValueTransferKind::SendToSelf));
Expand Down
33 changes: 16 additions & 17 deletions zingolib/src/wallet/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl LightWallet {
#[allow(clippy::type_complexity)]
async fn get_filtered_balance<D>(
&self,
filters: &[Box<dyn Fn(&&D::WalletNote, &TransactionRecord) -> bool + '_>],
filter_function: Box<dyn Fn(&&D::WalletNote, &TransactionRecord) -> bool + '_>,
) -> Option<u64>
where
D: DomainWalletExt,
Expand Down Expand Up @@ -67,10 +67,8 @@ impl LightWallet {
let mut selected_notes: Box<dyn Iterator<Item = &D::WalletNote>> =
Box::new(D::WalletNote::transaction_metadata_notes(transaction).iter());
// All filters in iterator are applied, by this loop
for filtering_fn in filters {
selected_notes =
Box::new(selected_notes.filter(|nnmd| filtering_fn(nnmd, transaction)))
}
selected_notes =
Box::new(selected_notes.filter(|nnmd| filter_function(nnmd, transaction)));
selected_notes
.map(|notedata| {
if notedata.spending_tx_status().is_none() {
Expand Down Expand Up @@ -120,19 +118,19 @@ impl LightWallet {
<D as Domain>::Note: PartialEq + Clone,
{
#[allow(clippy::type_complexity)]
let filters: &[Box<dyn Fn(&&D::WalletNote, &TransactionRecord) -> bool>] = &[
Box::new(|_, transaction| transaction.status.is_confirmed()),
Box::new(|nnmd, _| !nnmd.pending_receipt()),
];
self.get_filtered_balance::<D>(filters).await
let filter_function: Box<dyn Fn(&&D::WalletNote, &TransactionRecord) -> bool> =
Box::new(|nnmd, transaction| {
transaction.status.is_confirmed() && !nnmd.pending_receipt()
});
self.get_filtered_balance::<D>(filter_function).await
}
/// The amount in pending notes, not yet on chain
pub async fn pending_balance<D: DomainWalletExt>(&self) -> Option<u64>
where
<D as Domain>::Recipient: Recipient,
<D as Domain>::Note: PartialEq + Clone,
{
self.get_filtered_balance::<D>(&[Box::new(|note, _| note.pending_receipt())])
self.get_filtered_balance::<D>(Box::new(|note, _| note.pending_receipt()))
.await
}

Expand All @@ -144,12 +142,13 @@ impl LightWallet {
<D as Domain>::Note: PartialEq + Clone,
{
#[allow(clippy::type_complexity)]
let filters: &[Box<dyn Fn(&&D::WalletNote, &TransactionRecord) -> bool>] = &[
Box::new(|_, transaction| transaction.status.is_confirmed()),
Box::new(|note, _| !note.pending_receipt()),
Box::new(|note, _| note.value() >= MARGINAL_FEE.into_u64()),
];
self.get_filtered_balance::<D>(filters).await
let filter_function: Box<dyn Fn(&&D::WalletNote, &TransactionRecord) -> bool> =
Box::new(|note, transaction| {
transaction.status.is_confirmed()
&& !note.pending_receipt()
&& note.value() >= MARGINAL_FEE.into_u64()
});
self.get_filtered_balance::<D>(filter_function).await
}

/// Returns total balance of all shielded pools excluding any notes with value less than marginal fee
Expand Down

0 comments on commit 7666df9

Please sign in to comment.