|
40 | 40 | //! # use bdk_chain::example_utils::*; |
41 | 41 | //! # use bitcoin::Transaction; |
42 | 42 | //! # 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(); |
45 | 44 | //! |
46 | 45 | //! // 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); |
48 | 52 | //! |
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); |
51 | 54 | //! ``` |
52 | 55 | //! |
53 | | -//! A [`TxGraph`] can also be updated with another [`TxGraph`]. |
| 56 | +//! A [`TxGraph`] can also be updated with another [`TxGraph`] which merges them together. |
54 | 57 | //! |
55 | 58 | //! ``` |
56 | | -//! # use bdk_chain::BlockId; |
| 59 | +//! # use bdk_chain::{Append, BlockId}; |
57 | 60 | //! # use bdk_chain::tx_graph::TxGraph; |
58 | 61 | //! # use bdk_chain::example_utils::*; |
59 | 62 | //! # use bitcoin::Transaction; |
|
67 | 70 | //! |
68 | 71 | //! // if we apply it again, the resulting changeset will be empty |
69 | 72 | //! let changeset = graph.apply_update(update); |
70 | | -//! assert!({ |
71 | | -//! use bdk_chain::Append; |
72 | | -//! changeset.is_empty() |
73 | | -//! }); |
| 73 | +//! assert!(changeset.is_empty()); |
74 | 74 | //! ``` |
75 | 75 | //! [`try_get_chain_position`]: TxGraph::try_get_chain_position |
76 | 76 | //! [`insert_txout`]: TxGraph::insert_txout |
|
0 commit comments