]> Untitled Git - bdk/commitdiff
refactor(chain)!: Rename `CanonicalViewTx` to `CanonicalTx`
author志宇 <hello@evanlinjin.me>
Fri, 12 Sep 2025 06:11:28 +0000 (06:11 +0000)
committer志宇 <hello@evanlinjin.me>
Wed, 17 Sep 2025 23:46:29 +0000 (23:46 +0000)
Also update submodule-level docs for `tx_graph`'s Canonicalization
section.

crates/chain/src/canonical_view.rs
crates/chain/src/tx_graph.rs

index 83dfd4215e029b27af9ae701be71650505d918b9..c6b985e6ab72531ce95a8e59b422244b694822c2 100644 (file)
@@ -41,7 +41,7 @@ use crate::{
 /// conflicted). It includes the transaction itself along with its position in the chain (confirmed
 /// or unconfirmed).
 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
-pub struct CanonicalViewTx<A> {
+pub struct CanonicalTx<A> {
     /// The position of this transaction in the chain.
     ///
     /// This indicates whether the transaction is confirmed (and at what height) or
@@ -228,11 +228,11 @@ impl<A: Anchor> CanonicalView<A> {
     ///     println!("Found tx {} at position {:?}", canonical_tx.txid, canonical_tx.pos);
     /// }
     /// ```
-    pub fn tx(&self, txid: Txid) -> Option<CanonicalViewTx<A>> {
+    pub fn tx(&self, txid: Txid) -> Option<CanonicalTx<A>> {
         self.txs
             .get(&txid)
             .cloned()
-            .map(|(tx, pos)| CanonicalViewTx { pos, txid, tx })
+            .map(|(tx, pos)| CanonicalTx { pos, txid, tx })
     }
 
     /// Get a single canonical transaction output.
@@ -302,12 +302,10 @@ impl<A: Anchor> CanonicalView<A> {
     /// // Get the total number of canonical transactions
     /// println!("Total canonical transactions: {}", view.txs().len());
     /// ```
-    pub fn txs(
-        &self,
-    ) -> impl ExactSizeIterator<Item = CanonicalViewTx<A>> + DoubleEndedIterator + '_ {
+    pub fn txs(&self) -> impl ExactSizeIterator<Item = CanonicalTx<A>> + DoubleEndedIterator + '_ {
         self.order.iter().map(|&txid| {
             let (tx, pos) = self.txs[&txid].clone();
-            CanonicalViewTx { pos, txid, tx }
+            CanonicalTx { pos, txid, tx }
         })
     }
 
index 012810293820d85d3373218c64384edf9ace2460..97d4ecc024e798cabaa57193a3959670f5a99b25 100644 (file)
 //! Conflicting transactions are allowed to coexist within a [`TxGraph`]. A process called
 //! canonicalization is required to get a conflict-free view of transactions.
 //!
-//! * [`list_canonical_txs`](TxGraph::list_canonical_txs) lists canonical transactions.
-//! * [`filter_chain_txouts`](TxGraph::filter_chain_txouts) filters out canonical outputs from a
-//!   list of outpoints.
-//! * [`filter_chain_unspents`](TxGraph::filter_chain_unspents) filters out canonical unspent
-//!   outputs from a list of outpoints.
-//! * [`balance`](TxGraph::balance) gets the total sum of unspent outputs filtered from a list of
-//!   outpoints.
-//! * [`canonical_iter`](TxGraph::canonical_iter) returns the [`CanonicalIter`] which contains all
-//!   of the canonicalization logic.
+//! * [`canonical_iter`](TxGraph::canonical_iter) returns a [`CanonicalIter`] which performs
+//!   incremental canonicalization. This is useful when you only need to check specific transactions
+//!   (e.g., verifying whether a few unconfirmed transactions are canonical) without computing the
+//!   entire canonical view.
+//! * [`canonical_view`](TxGraph::canonical_view) returns a [`CanonicalView`] which provides a
+//!   complete canonical view of the graph. This is required for typical wallet operations like
+//!   querying balances, listing outputs, transactions, and UTXOs. You must construct this first
+//!   before performing these operations.
 //!
 //! All these methods require a `chain` and `chain_tip` argument. The `chain` must be a
 //! [`ChainOracle`] implementation (such as [`LocalChain`](crate::local_chain::LocalChain)) which