@@ -60,12 +60,12 @@ pub struct CanonicalTx<A> {
6060/// provides methods to query transaction data, unspent outputs, and balances.
6161///
6262/// The view maintains:
63- /// - An ordered list of canonical transactions (WIP)
63+ /// - An ordered list of canonical transactions in topological-spending order
6464/// - A mapping of outpoints to the transactions that spend them
6565/// - The chain tip used for canonicalization
6666#[ derive( Debug ) ]
6767pub struct CanonicalView < A > {
68- /// Ordered list of transaction IDs in canonical order.
68+ /// Ordered list of transaction IDs in topological-spending order.
6969 order : Vec < Txid > ,
7070 /// Map of transaction IDs to their transaction data and chain position.
7171 txs : HashMap < Txid , ( Arc < Transaction > , ChainPosition < A > ) > ,
@@ -119,7 +119,7 @@ impl<A: Anchor> CanonicalView<A> {
119119 } ;
120120
121121 for r in CanonicalIter :: new ( tx_graph, chain, chain_tip, params) {
122- let ( txid, tx, why ) = r?;
122+ let ( txid, tx, reason ) = r?;
123123
124124 let tx_node = match tx_graph. get_tx_node ( txid) {
125125 Some ( tx_node) => tx_node,
@@ -137,7 +137,7 @@ impl<A: Anchor> CanonicalView<A> {
137137 . extend ( tx. input . iter ( ) . map ( |txin| ( txin. previous_output , txid) ) ) ;
138138 }
139139
140- let pos = match why {
140+ let pos = match reason {
141141 CanonicalReason :: Assumed { descendant } => match descendant {
142142 Some ( _) => match find_direct_anchor ( & tx_node, chain, chain_tip) ? {
143143 Some ( anchor) => ChainPosition :: Confirmed {
@@ -189,8 +189,8 @@ impl<A: Anchor> CanonicalView<A> {
189189
190190 /// Get a single canonical transaction by its transaction ID.
191191 ///
192- /// Returns `Some(CanonicalViewTx )` if the transaction exists in the canonical view,
193- /// or `None` if the transaction doesn't exist or was excluded due to conflicts .
192+ /// Returns `Some(CanonicalTx )` if the transaction exists in the canonical view,
193+ /// or `None` if it doesn't exist.
194194 pub fn tx ( & self , txid : Txid ) -> Option < CanonicalTx < A > > {
195195 self . txs
196196 . get ( & txid)
@@ -206,7 +206,6 @@ impl<A: Anchor> CanonicalView<A> {
206206 /// Returns `None` if:
207207 /// - The transaction doesn't exist in the canonical view
208208 /// - The output index is out of bounds
209- /// - The transaction was excluded due to conflicts
210209 pub fn txout ( & self , op : OutPoint ) -> Option < FullTxOut < A > > {
211210 let ( tx, pos) = self . txs . get ( & op. txid ) ?;
212211 let vout: usize = op. vout . try_into ( ) . ok ( ) ?;
@@ -226,8 +225,9 @@ impl<A: Anchor> CanonicalView<A> {
226225
227226 /// Get an iterator over all canonical transactions in order.
228227 ///
229- /// Transactions are returned in canonical order, with confirmed transactions ordered by
230- /// block height and position, followed by unconfirmed transactions.
228+ /// Transactions are returned in topological-spending order, where ancestors appear before
229+ /// their descendants (i.e., transactions that spend outputs come after the transactions
230+ /// that create those outputs).
231231 ///
232232 /// # Example
233233 ///
@@ -326,16 +326,14 @@ impl<A: Anchor> CanonicalView<A> {
326326 /// * `trust_predicate` - Function that returns `true` for trusted scripts. Trusted outputs
327327 /// count toward `trusted_pending` balance, while untrusted ones count toward
328328 /// `untrusted_pending`
329- /// * `min_confirmations ` - Minimum confirmations required for an output to be considered
330- /// confirmed. Outputs with fewer confirmations are treated as pending.
329+ /// * `additional_confirmations ` - Additional confirmations required beyond the first one.
330+ /// Outputs with fewer than (1 + additional_confirmations) are treated as pending.
331331 ///
332- /// # Minimum Confirmations
332+ /// # Additional Confirmations
333333 ///
334- /// The `min_confirmations` parameter controls when outputs are considered confirmed. A
335- /// `min_confirmations` value of `0` is equivalent to `1` (require at least 1 confirmation).
336- ///
337- /// Outputs with fewer than `min_confirmations` are categorized as pending (trusted or
338- /// untrusted based on the trust predicate).
334+ /// The `additional_confirmations` parameter specifies how many confirmations beyond the
335+ /// first one are required. For example, `additional_confirmations = 5` means 6 total
336+ /// confirmations are required (1 + 5).
339337 ///
340338 /// # Example
341339 ///
@@ -351,14 +349,14 @@ impl<A: Anchor> CanonicalView<A> {
351349 /// let balance = view.balance(
352350 /// indexer.outpoints().into_iter().map(|(k, op)| (k.clone(), *op)),
353351 /// |_keychain, _script| true, // Trust all outputs
354- /// 6 , // Require 6 confirmations
352+ /// 5 , // Require 6 confirmations (1 + 5)
355353 /// );
356354 /// ```
357355 pub fn balance < ' v , O : Clone + ' v > (
358356 & ' v self ,
359357 outpoints : impl IntoIterator < Item = ( O , OutPoint ) > + ' v ,
360358 mut trust_predicate : impl FnMut ( & O , ScriptBuf ) -> bool ,
361- min_confirmations : u32 ,
359+ additional_confirmations : u32 ,
362360 ) -> Balance {
363361 let mut immature = Amount :: ZERO ;
364362 let mut trusted_pending = Amount :: ZERO ;
@@ -374,9 +372,9 @@ impl<A: Anchor> CanonicalView<A> {
374372 . height
375373 . saturating_sub ( confirmation_height)
376374 . saturating_add ( 1 ) ;
377- let min_confirmations = min_confirmations . max ( 1 ) ; // 0 and 1 behave identically
375+ let required_confirmations = 1 + additional_confirmations ;
378376
379- if confirmations < min_confirmations {
377+ if confirmations < required_confirmations {
380378 // Not enough confirmations, treat as trusted/untrusted pending
381379 if trust_predicate ( & spk_i, txout. txout . script_pubkey ) {
382380 trusted_pending += txout. txout . value ;
0 commit comments