@@ -19,6 +19,7 @@ use alloc::{
1919 sync:: Arc ,
2020 vec:: Vec ,
2121} ;
22+ use chain:: Indexer ;
2223use core:: { cmp:: Ordering , fmt, mem, ops:: Deref } ;
2324
2425use 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+ /// A transaction is relevant when it spends from or spends to at least one tracked output. A
1069+ /// transaction 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`].
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