From: uvuvuwu <2003danielsu@gmail.com> Date: Sun, 6 Apr 2025 00:03:47 +0000 (+1200) Subject: feat(chain): Add method for constructing `TxGraph` from a `ChangeSet` X-Git-Tag: core-0.5.0~5^2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/scripts/static/enum.IncompleteBuilderError.html?a=commitdiff_plain;h=f68cfa8afb7602d36a9b5c41552b2fc6de2c9ac2;p=bdk feat(chain): Add method for constructing `TxGraph` from a `ChangeSet` * Added a `from_changeset()` function to `TxGraph` implementation * This function initializes a new `TxGraph` and applies the given `ChangeSet` * The method allows constructing a `TxGraph` directly from a `ChangeSet`, simplifying graph creation. --- diff --git a/crates/chain/src/tx_graph.rs b/crates/chain/src/tx_graph.rs index 4c299035..0ceea3e3 100644 --- a/crates/chain/src/tx_graph.rs +++ b/crates/chain/src/tx_graph.rs @@ -1216,6 +1216,13 @@ impl TxGraph { self.try_list_expected_spk_txids(chain, chain_tip, indexer, spk_index_range) .map(|r| r.expect("infallible")) } + + /// Construct a `TxGraph` from a `changeset`. + pub fn from_changeset(changeset: ChangeSet) -> Self { + let mut graph = Self::default(); + graph.apply_changeset(changeset); + graph + } } /// The [`ChangeSet`] represents changes to a [`TxGraph`].