diff --git a/crates/chain/src/tx_data_traits.rs b/crates/chain/src/tx_data_traits.rs index 811b1ff414..0828ec9785 100644 --- a/crates/chain/src/tx_data_traits.rs +++ b/crates/chain/src/tx_data_traits.rs @@ -44,6 +44,30 @@ impl ForEachTxOut for Transaction { /// assume that transaction A is also confirmed in the best chain. This does not necessarily mean /// that transaction A is confirmed in block B. It could also mean transaction A is confirmed in a /// parent block of B. +/// +/// ``` +/// # use crate::local_chain::LocalChain; +/// # use crate::tx_graph::TxGraph; +/// # use crate::BlockId; +/// # use crate::example_utils::*; +/// # use bitcoin::hashes::Hash; +/// // Initialize the local chain with two blocks. +/// let chain = LocalChain::from_blocks([(1, Hash::hash("first".as_bytes())).into(), (2, Hash::hash("second".as_bytes()))].into_iter().collect()); +/// // Insert transaction into TxGraph with different anchor types. +/// let tx = tx_from_hex(RAW_TX_1); +/// let mut graph_a = TxGraph::::default(); +/// let _ = graph_a.insert_tx(tx.clone()); +/// let mut graph_b = TxGraph::::default(); +/// let _ = graph_b.insert_tx(tx.clone()); +/// +/// // Insert different anchor types for the same transaction. +/// // When using the BlockId as anchor, the anchor block is the +/// // confirmation block of the transaction. Where as when using +/// // the ConfirmationHeightAnchor, the anchor block is a bound on +/// // the confirmation block of the transaction. +/// graph_a.insert_anchor(tx.txid(), BlockId { height: 1, hash: Hash::hash("first".as_bytes()) }); +/// graph_a.insert_anchor(tx.txid(), ConfirmationHeightAnchor { anchor_block: BlockId { height: 2, hash: Hash::hash("second".as_bytes()) }, confirmation_height: 1 }); +/// ``` pub trait Anchor: core::fmt::Debug + Clone + Eq + PartialOrd + Ord + core::hash::Hash { /// Returns the [`BlockId`] that the associated blockchain data is "anchored" in. fn anchor_block(&self) -> BlockId;