From f68cfa8afb7602d36a9b5c41552b2fc6de2c9ac2 Mon Sep 17 00:00:00 2001 From: uvuvuwu <2003danielsu@gmail.com> Date: Sun, 6 Apr 2025 12:03:47 +1200 Subject: [PATCH] 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. --- crates/chain/src/tx_graph.rs | 7 +++++++ 1 file changed, 7 insertions(+) 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`]. -- 2.49.0