]> Untitled Git - bdk/commitdiff
chore(chain): Improve TxGraph::ChangeSet docs
authorLLFourn <lloyd.fourn@gmail.com>
Fri, 9 Feb 2024 22:13:08 +0000 (09:13 +1100)
committerLLFourn <lloyd.fourn@gmail.com>
Fri, 9 Feb 2024 22:13:08 +0000 (09:13 +1100)
crates/chain/src/tx_graph.rs

index 75a81d4ac88a655015da8967b5dbcb99945ee890..4dd7f0a259d2f5e6c9551511ebae3b0723023244 100644 (file)
 //! # use bdk_chain::example_utils::*;
 //! # use bitcoin::Transaction;
 //! # let tx_a = tx_from_hex(RAW_TX_1);
-//! let mut graph: TxGraph = TxGraph::default();
-//! let mut another_graph: TxGraph = TxGraph::default();
+//! let mut tx_graph: TxGraph = TxGraph::default();
 //!
 //! // insert a transaction
-//! let changeset = graph.insert_tx(tx_a);
+//! let changeset = tx_graph.insert_tx(tx_a);
+//!
+//! // We can restore the state of the `tx_graph` by applying all
+//! // the changesets obtained by mutating the original (the order doesn't matter).
+//! let mut restored_tx_graph: TxGraph = TxGraph::default();
+//! restored_tx_graph.apply_changeset(changeset);
 //!
-//! // the resulting changeset can be applied to another tx graph
-//! another_graph.apply_changeset(changeset);
+//! assert_eq!(tx_graph, restored_tx_graph);
 //! ```
 //!
-//! A [`TxGraph`] can also be updated with another [`TxGraph`].
+//! A [`TxGraph`] can also be updated with another [`TxGraph`] which merges them together.
 //!
 //! ```
-//! # use bdk_chain::BlockId;
+//! # use bdk_chain::{Append, BlockId};
 //! # use bdk_chain::tx_graph::TxGraph;
 //! # use bdk_chain::example_utils::*;
 //! # use bitcoin::Transaction;
 //!
 //! // if we apply it again, the resulting changeset will be empty
 //! let changeset = graph.apply_update(update);
-//! assert!({
-//!     use bdk_chain::Append;
-//!     changeset.is_empty()
-//! });
+//! assert!(changeset.is_empty());
 //! ```
 //! [`try_get_chain_position`]: TxGraph::try_get_chain_position
 //! [`insert_txout`]: TxGraph::insert_txout