@@ -60,12 +60,12 @@ pub struct CanonicalTx<A> {
60
60
/// provides methods to query transaction data, unspent outputs, and balances.
61
61
///
62
62
/// The view maintains:
63
- /// - An ordered list of canonical transactions (WIP)
63
+ /// - An ordered list of canonical transactions in topological-spending order
64
64
/// - A mapping of outpoints to the transactions that spend them
65
65
/// - The chain tip used for canonicalization
66
66
#[ derive( Debug ) ]
67
67
pub struct CanonicalView < A > {
68
- /// Ordered list of transaction IDs in canonical order.
68
+ /// Ordered list of transaction IDs in topological-spending order.
69
69
order : Vec < Txid > ,
70
70
/// Map of transaction IDs to their transaction data and chain position.
71
71
txs : HashMap < Txid , ( Arc < Transaction > , ChainPosition < A > ) > ,
@@ -119,7 +119,7 @@ impl<A: Anchor> CanonicalView<A> {
119
119
} ;
120
120
121
121
for r in CanonicalIter :: new ( tx_graph, chain, chain_tip, params) {
122
- let ( txid, tx, why ) = r?;
122
+ let ( txid, tx, reason ) = r?;
123
123
124
124
let tx_node = match tx_graph. get_tx_node ( txid) {
125
125
Some ( tx_node) => tx_node,
@@ -137,7 +137,7 @@ impl<A: Anchor> CanonicalView<A> {
137
137
. extend ( tx. input . iter ( ) . map ( |txin| ( txin. previous_output , txid) ) ) ;
138
138
}
139
139
140
- let pos = match why {
140
+ let pos = match reason {
141
141
CanonicalReason :: Assumed { descendant } => match descendant {
142
142
Some ( _) => match find_direct_anchor ( & tx_node, chain, chain_tip) ? {
143
143
Some ( anchor) => ChainPosition :: Confirmed {
@@ -189,8 +189,8 @@ impl<A: Anchor> CanonicalView<A> {
189
189
190
190
/// Get a single canonical transaction by its transaction ID.
191
191
///
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.
194
194
pub fn tx ( & self , txid : Txid ) -> Option < CanonicalTx < A > > {
195
195
self . txs
196
196
. get ( & txid)
@@ -206,7 +206,6 @@ impl<A: Anchor> CanonicalView<A> {
206
206
/// Returns `None` if:
207
207
/// - The transaction doesn't exist in the canonical view
208
208
/// - The output index is out of bounds
209
- /// - The transaction was excluded due to conflicts
210
209
pub fn txout ( & self , op : OutPoint ) -> Option < FullTxOut < A > > {
211
210
let ( tx, pos) = self . txs . get ( & op. txid ) ?;
212
211
let vout: usize = op. vout . try_into ( ) . ok ( ) ?;
@@ -226,8 +225,9 @@ impl<A: Anchor> CanonicalView<A> {
226
225
227
226
/// Get an iterator over all canonical transactions in order.
228
227
///
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).
231
231
///
232
232
/// # Example
233
233
///
@@ -326,16 +326,14 @@ impl<A: Anchor> CanonicalView<A> {
326
326
/// * `trust_predicate` - Function that returns `true` for trusted scripts. Trusted outputs
327
327
/// count toward `trusted_pending` balance, while untrusted ones count toward
328
328
/// `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.
331
331
///
332
- /// # Minimum Confirmations
332
+ /// # Additional Confirmations
333
333
///
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).
339
337
///
340
338
/// # Example
341
339
///
@@ -351,14 +349,14 @@ impl<A: Anchor> CanonicalView<A> {
351
349
/// let balance = view.balance(
352
350
/// indexer.outpoints().into_iter().map(|(k, op)| (k.clone(), *op)),
353
351
/// |_keychain, _script| true, // Trust all outputs
354
- /// 6 , // Require 6 confirmations
352
+ /// 5 , // Require 6 confirmations (1 + 5)
355
353
/// );
356
354
/// ```
357
355
pub fn balance < ' v , O : Clone + ' v > (
358
356
& ' v self ,
359
357
outpoints : impl IntoIterator < Item = ( O , OutPoint ) > + ' v ,
360
358
mut trust_predicate : impl FnMut ( & O , ScriptBuf ) -> bool ,
361
- min_confirmations : u32 ,
359
+ additional_confirmations : u32 ,
362
360
) -> Balance {
363
361
let mut immature = Amount :: ZERO ;
364
362
let mut trusted_pending = Amount :: ZERO ;
@@ -374,9 +372,9 @@ impl<A: Anchor> CanonicalView<A> {
374
372
. height
375
373
. saturating_sub ( confirmation_height)
376
374
. saturating_add ( 1 ) ;
377
- let min_confirmations = min_confirmations . max ( 1 ) ; // 0 and 1 behave identically
375
+ let required_confirmations = 1 + additional_confirmations ;
378
376
379
- if confirmations < min_confirmations {
377
+ if confirmations < required_confirmations {
380
378
// Not enough confirmations, treat as trusted/untrusted pending
381
379
if trust_predicate ( & spk_i, txout. txout . script_pubkey ) {
382
380
trusted_pending += txout. txout . value ;
0 commit comments