@@ -19,6 +19,7 @@ use alloc::{
19
19
sync:: Arc ,
20
20
vec:: Vec ,
21
21
} ;
22
+ use chain:: Indexer ;
22
23
use core:: { cmp:: Ordering , fmt, mem, ops:: Deref } ;
23
24
24
25
use bdk_chain:: {
@@ -1062,14 +1063,30 @@ impl Wallet {
1062
1063
. find ( |tx| tx. tx_node . txid == txid)
1063
1064
}
1064
1065
1065
- /// Iterate over the transactions in the wallet.
1066
+ /// Iterate over relevant and canonical transactions in the wallet.
1067
+ ///
1068
+ /// A transaction is relevant when it spends from or spends to at least one tracked ouput. A
1069
+ /// transactions is canonical when it is confirmed in the best chain, or does not conflict
1070
+ /// with any transaction 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`].
1066
1077
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
1069
1081
. list_canonical_txs ( & self . chain , self . chain . tip ( ) . block_id ( ) )
1082
+ . filter ( |c_tx| tx_index. is_tx_relevant ( & c_tx. tx_node . tx ) )
1070
1083
}
1071
1084
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.
1073
1090
///
1074
1091
/// # Example
1075
1092
///
0 commit comments