Skip to content

Commit

Permalink
fix(wallet): transactions method should only return relevant txs
Browse files Browse the repository at this point in the history
Also update documentation.
  • Loading branch information
evanlinjin committed Dec 17, 2024
1 parent dbc6a1e commit 2df73bf
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use alloc::{
sync::Arc,
vec::Vec,
};
use chain::Indexer;
use core::{cmp::Ordering, fmt, mem, ops::Deref};

use bdk_chain::{
Expand Down Expand Up @@ -1062,14 +1063,30 @@ impl Wallet {
.find(|tx| tx.tx_node.txid == txid)
}

/// Iterate over the transactions in the wallet.
/// Iterate over relevant and canonical transactions in the wallet.
///
/// Transactions are relevant when it spends from or spends to at least one tracked ouput.
/// Transactions are canonical when they are confirmed in the best chain, or do not conflict
/// with any transactions confirmed in the best chain.
///
/// To iterate over all transactions, including those that are irrelevant and not canonical, use
/// [`TxGraph::full_txs`].
///
/// To iterate over all canonical transactions, including those that are irrelevant, use
/// [`TxGraph::list_canonical_txs`].
pub fn transactions(&self) -> impl Iterator<Item = WalletTx> + '_ {
self.indexed_graph
.graph()
let tx_graph = self.indexed_graph.graph();
let tx_index = &self.indexed_graph.index;
tx_graph
.list_canonical_txs(&self.chain, self.chain.tip().block_id())
.filter(|c_tx| tx_index.is_tx_relevant(&c_tx.tx_node.tx))
}

/// Array of transactions in the wallet sorted with a comparator function.
/// Array of relevant and canonical transactions in the wallet sorted with a comparator
/// function.
///
/// This is a helper method equivalent to collecting the result of [`Wallet::transactions`]
/// into a [`Vec`] and then sorting it.
///
/// # Example
///
Expand Down

0 comments on commit 2df73bf

Please # to comment.