Skip to content

Commit 388ac7a

Browse files
evanlinjinoleonardolima
authored andcommitted
refactor(chain)!: Rename CanonicalViewTx to CanonicalTx
Also update submodule-level docs for `tx_graph`'s Canonicalization section.
1 parent 89824b6 commit 388ac7a

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

crates/chain/src/canonical_view.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use crate::{
4141
/// conflicted). It includes the transaction itself along with its position in the chain (confirmed
4242
/// or unconfirmed).
4343
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
44-
pub struct CanonicalViewTx<A> {
44+
pub struct CanonicalTx<A> {
4545
/// The position of this transaction in the chain.
4646
///
4747
/// This indicates whether the transaction is confirmed (and at what height) or
@@ -228,11 +228,11 @@ impl<A: Anchor> CanonicalView<A> {
228228
/// println!("Found tx {} at position {:?}", canonical_tx.txid, canonical_tx.pos);
229229
/// }
230230
/// ```
231-
pub fn tx(&self, txid: Txid) -> Option<CanonicalViewTx<A>> {
231+
pub fn tx(&self, txid: Txid) -> Option<CanonicalTx<A>> {
232232
self.txs
233233
.get(&txid)
234234
.cloned()
235-
.map(|(tx, pos)| CanonicalViewTx { pos, txid, tx })
235+
.map(|(tx, pos)| CanonicalTx { pos, txid, tx })
236236
}
237237

238238
/// Get a single canonical transaction output.
@@ -302,12 +302,10 @@ impl<A: Anchor> CanonicalView<A> {
302302
/// // Get the total number of canonical transactions
303303
/// println!("Total canonical transactions: {}", view.txs().len());
304304
/// ```
305-
pub fn txs(
306-
&self,
307-
) -> impl ExactSizeIterator<Item = CanonicalViewTx<A>> + DoubleEndedIterator + '_ {
305+
pub fn txs(&self) -> impl ExactSizeIterator<Item = CanonicalTx<A>> + DoubleEndedIterator + '_ {
308306
self.order.iter().map(|&txid| {
309307
let (tx, pos) = self.txs[&txid].clone();
310-
CanonicalViewTx { pos, txid, tx }
308+
CanonicalTx { pos, txid, tx }
311309
})
312310
}
313311

crates/chain/src/tx_graph.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
//! Conflicting transactions are allowed to coexist within a [`TxGraph`]. A process called
2222
//! canonicalization is required to get a conflict-free view of transactions.
2323
//!
24-
//! * [`list_canonical_txs`](TxGraph::list_canonical_txs) lists canonical transactions.
25-
//! * [`filter_chain_txouts`](TxGraph::filter_chain_txouts) filters out canonical outputs from a
26-
//! list of outpoints.
27-
//! * [`filter_chain_unspents`](TxGraph::filter_chain_unspents) filters out canonical unspent
28-
//! outputs from a list of outpoints.
29-
//! * [`balance`](TxGraph::balance) gets the total sum of unspent outputs filtered from a list of
30-
//! outpoints.
31-
//! * [`canonical_iter`](TxGraph::canonical_iter) returns the [`CanonicalIter`] which contains all
32-
//! of the canonicalization logic.
24+
//! * [`canonical_iter`](TxGraph::canonical_iter) returns a [`CanonicalIter`] which performs
25+
//! incremental canonicalization. This is useful when you only need to check specific transactions
26+
//! (e.g., verifying whether a few unconfirmed transactions are canonical) without computing the
27+
//! entire canonical view.
28+
//! * [`canonical_view`](TxGraph::canonical_view) returns a [`CanonicalView`] which provides a
29+
//! complete canonical view of the graph. This is required for typical wallet operations like
30+
//! querying balances, listing outputs, transactions, and UTXOs. You must construct this first
31+
//! before performing these operations.
3332
//!
3433
//! All these methods require a `chain` and `chain_tip` argument. The `chain` must be a
3534
//! [`ChainOracle`] implementation (such as [`LocalChain`](crate::local_chain::LocalChain)) which

0 commit comments

Comments
 (0)