Skip to content

Commit 13ab5a8

Browse files
committed
chore(chain): Improve TxGraph::ChangeSet docs
1 parent dbbd514 commit 13ab5a8

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

crates/chain/src/tx_graph.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,23 @@
4040
//! # use bdk_chain::example_utils::*;
4141
//! # use bitcoin::Transaction;
4242
//! # let tx_a = tx_from_hex(RAW_TX_1);
43-
//! let mut graph: TxGraph = TxGraph::default();
44-
//! let mut another_graph: TxGraph = TxGraph::default();
43+
//! let mut tx_graph: TxGraph = TxGraph::default();
4544
//!
4645
//! // insert a transaction
47-
//! let changeset = graph.insert_tx(tx_a);
46+
//! let changeset = tx_graph.insert_tx(tx_a);
47+
//!
48+
//! // We can restore the state of the `tx_graph` by applying all
49+
//! // the changesets obtained by mutating the original (the order doesn't matter).
50+
//! let mut restored_tx_graph: TxGraph = TxGraph::default();
51+
//! restored_tx_graph.apply_changeset(changeset);
4852
//!
49-
//! // the resulting changeset can be applied to another tx graph
50-
//! another_graph.apply_changeset(changeset);
53+
//! assert_eq!(tx_graph, restored_tx_graph);
5154
//! ```
5255
//!
53-
//! A [`TxGraph`] can also be updated with another [`TxGraph`].
56+
//! A [`TxGraph`] can also be updated with another [`TxGraph`] which merges them together.
5457
//!
5558
//! ```
56-
//! # use bdk_chain::BlockId;
59+
//! # use bdk_chain::{Append, BlockId};
5760
//! # use bdk_chain::tx_graph::TxGraph;
5861
//! # use bdk_chain::example_utils::*;
5962
//! # use bitcoin::Transaction;
@@ -67,10 +70,7 @@
6770
//!
6871
//! // if we apply it again, the resulting changeset will be empty
6972
//! let changeset = graph.apply_update(update);
70-
//! assert!({
71-
//! use bdk_chain::Append;
72-
//! changeset.is_empty()
73-
//! });
73+
//! assert!(changeset.is_empty());
7474
//! ```
7575
//! [`try_get_chain_position`]: TxGraph::try_get_chain_position
7676
//! [`insert_txout`]: TxGraph::insert_txout

0 commit comments

Comments
 (0)