From 8cd0328eec0b55f10dd085597a435b689b37444a Mon Sep 17 00:00:00 2001 From: rajarshimaitra Date: Thu, 27 Apr 2023 19:38:35 +0530 Subject: [PATCH] [bdk_chain_redesign] Implement `OwnedIndexer` for indexers `SpkTxOutIndex` and `KeychainTxOutIndex` now both implement `OwnedIndexer`. --- crates/chain/src/keychain/txout_index.rs | 8 +++++++- crates/chain/src/spk_txout_index.rs | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/chain/src/keychain/txout_index.rs b/crates/chain/src/keychain/txout_index.rs index e4ac3ef4..fbe67d1f 100644 --- a/crates/chain/src/keychain/txout_index.rs +++ b/crates/chain/src/keychain/txout_index.rs @@ -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 Indexer for KeychainTxOutIndex { } } +impl OwnedIndexer for KeychainTxOutIndex { + fn is_spk_owned(&self, spk: &Script) -> bool { + self.inner().is_spk_owned(spk) + } +} + impl KeychainTxOutIndex { /// Scans an object for relevant outpoints, which are stored and indexed internally. /// diff --git a/crates/chain/src/spk_txout_index.rs b/crates/chain/src/spk_txout_index.rs index 3e89ba39..9fdf3bc0 100644 --- a/crates/chain/src/spk_txout_index.rs +++ b/crates/chain/src/spk_txout_index.rs @@ -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 Indexer for SpkTxOutIndex { } } +impl OwnedIndexer for SpkTxOutIndex { + 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.