Skip to content

Commit 2df73bf

Browse files
committed
fix(wallet): transactions method should only return relevant txs
Also update documentation.
1 parent dbc6a1e commit 2df73bf

File tree

1 file changed

+21
-4
lines changed
  • crates/wallet/src/wallet

1 file changed

+21
-4
lines changed

crates/wallet/src/wallet/mod.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use alloc::{
1919
sync::Arc,
2020
vec::Vec,
2121
};
22+
use chain::Indexer;
2223
use core::{cmp::Ordering, fmt, mem, ops::Deref};
2324

2425
use bdk_chain::{
@@ -1062,14 +1063,30 @@ impl Wallet {
10621063
.find(|tx| tx.tx_node.txid == txid)
10631064
}
10641065

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

1072-
/// Array of transactions in the wallet sorted with a comparator function.
1085+
/// Array of relevant and canonical transactions in the wallet sorted with a comparator
1086+
/// function.
1087+
///
1088+
/// This is a helper method equivalent to collecting the result of [`Wallet::transactions`]
1089+
/// into a [`Vec`] and then sorting it.
10731090
///
10741091
/// # Example
10751092
///

0 commit comments

Comments
 (0)