]> Untitled Git - bdk/commitdiff
[bdk_chain_redesign] Implement `OwnedIndexer` for indexers
authorrajarshimaitra <rajarshi149@gmail.com>
Thu, 27 Apr 2023 14:08:35 +0000 (19:38 +0530)
committer志宇 <hello@evanlinjin.me>
Fri, 28 Apr 2023 11:09:52 +0000 (19:09 +0800)
`SpkTxOutIndex` and `KeychainTxOutIndex` now both implement
`OwnedIndexer`.

crates/chain/src/keychain/txout_index.rs
crates/chain/src/spk_txout_index.rs

index e4ac3ef4c3cca16453f49da2ca4123fe219b91a6..fbe67d1fc84214d8102a6f4aac8a2b8187324a62 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
     collections::*,
-    indexed_tx_graph::Indexer,
+    indexed_tx_graph::{Indexer, OwnedIndexer},
     miniscript::{Descriptor, DescriptorPublicKey},
     ForEachTxOut, SpkTxOutIndex,
 };
@@ -111,6 +111,12 @@ impl<K: Clone + Ord + Debug + 'static> Indexer for KeychainTxOutIndex<K> {
     }
 }
 
+impl<K: Clone + Ord + Debug + 'static> OwnedIndexer for KeychainTxOutIndex<K> {
+    fn is_spk_owned(&self, spk: &Script) -> bool {
+        self.inner().is_spk_owned(spk)
+    }
+}
+
 impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
     /// Scans an object for relevant outpoints, which are stored and indexed internally.
     ///
index 3e89ba39d3733a73aa1cff64c180703f398b4f68..9fdf3bc04394159adf6107fdb775fee51bdc1983 100644 (file)
@@ -2,7 +2,7 @@ use core::ops::RangeBounds;
 
 use crate::{
     collections::{hash_map::Entry, BTreeMap, BTreeSet, HashMap},
-    indexed_tx_graph::Indexer,
+    indexed_tx_graph::{Indexer, OwnedIndexer},
     ForEachTxOut,
 };
 use bitcoin::{self, OutPoint, Script, Transaction, TxOut, Txid};
@@ -75,6 +75,12 @@ impl<I: Clone + Ord + 'static> Indexer for SpkTxOutIndex<I> {
     }
 }
 
+impl<I: Clone + Ord + 'static> OwnedIndexer for SpkTxOutIndex<I> {
+    fn is_spk_owned(&self, spk: &Script) -> bool {
+        self.spk_indices.get(spk).is_some()
+    }
+}
+
 /// This macro is used instead of a member function of `SpkTxOutIndex`, which would result in a
 /// compiler error[E0521]: "borrowed data escapes out of closure" when we attempt to take a
 /// reference out of the `ForEachTxOut` closure during scanning.