Skip to content

Commit

Permalink
[bdk_chain_redesign] Implement OwnedIndexer for indexers
Browse files Browse the repository at this point in the history
`SpkTxOutIndex` and `KeychainTxOutIndex` now both implement
`OwnedIndexer`.
  • Loading branch information
rajarshimaitra authored and evanlinjin committed Apr 28, 2023
1 parent 911af34 commit 8cd0328
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion crates/chain/src/keychain/txout_index.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
collections::*,
indexed_tx_graph::Indexer,
indexed_tx_graph::{Indexer, OwnedIndexer},
miniscript::{Descriptor, DescriptorPublicKey},
ForEachTxOut, SpkTxOutIndex,
};
Expand Down Expand Up @@ -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.
///
Expand Down
8 changes: 7 additions & 1 deletion crates/chain/src/spk_txout_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8cd0328

Please sign in to comment.