]> Untitled Git - bdk/commitdiff
feat(chain): Add `KeychainTxOutIndex::from_changeset` constructor
author志宇 <hello@evanlinjin.me>
Fri, 23 May 2025 01:51:12 +0000 (11:51 +1000)
committer志宇 <hello@evanlinjin.me>
Fri, 23 May 2025 01:51:12 +0000 (11:51 +1000)
This incentivies constructing `KeychainTxOutIndex` from a changeset
before inserting descriptors (to make use of the spk cache).

crates/chain/src/indexer/keychain_txout.rs

index c8352eb2f0089e3e4cd1eb7877c46cabdaa1a859..55486e9e38729de78c5d507785931401aabd0a8d 100644 (file)
@@ -236,6 +236,13 @@ impl<K> KeychainTxOutIndex<K> {
 
 /// Methods that are *re-exposed* from the internal [`SpkTxOutIndex`].
 impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
+    /// Construct `KeychainTxOutIndex<K>` from the given `changeset`.
+    pub fn from_changeset(changeset: ChangeSet) -> Self {
+        let mut out = Self::default();
+        out.apply_changeset(changeset);
+        out
+    }
+
     /// Get the set of indexed outpoints, corresponding to tracked keychains.
     pub fn outpoints(&self) -> &BTreeSet<KeychainIndexed<K, OutPoint>> {
         self.inner.outpoints()