]> Untitled Git - bdk/commitdiff
feat(chain): Add method for constructing `TxGraph` from a `ChangeSet`
authoruvuvuwu <2003danielsu@gmail.com>
Sun, 6 Apr 2025 00:03:47 +0000 (12:03 +1200)
committeruvuvuwu <2003danielsu@gmail.com>
Mon, 7 Apr 2025 01:47:01 +0000 (13:47 +1200)
* 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

index 4c2990351c40cc9dc3453114a6b68bd51f982004..0ceea3e30acc0a06b3ce4ff22122d962dec94048 100644 (file)
@@ -1216,6 +1216,13 @@ impl<A: Anchor> TxGraph<A> {
         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<A>) -> Self {
+        let mut graph = Self::default();
+        graph.apply_changeset(changeset);
+        graph
+    }
 }
 
 /// The [`ChangeSet`] represents changes to a [`TxGraph`].