[bdk_chain_redesign] Implement OwnedIndexer for indexers

`SpkTxOutIndex` and `KeychainTxOutIndex` now both implement
`OwnedIndexer`.
This commit is contained in:
rajarshimaitra 2023-04-27 19:38:35 +05:30 committed by 志宇
parent 911af34f50
commit 8cd0328eec
No known key found for this signature in database
GPG Key ID: F6345C9837C2BDE8
2 changed files with 14 additions and 2 deletions

View 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.
///

View 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.