bdk_chain/indexer.rs
1//! [`Indexer`] provides utilities for indexing transaction data.
2
3use bitcoin::{OutPoint, Transaction, TxOut};
4
5#[cfg(feature = "miniscript")]
6pub mod keychain_txout;
7pub mod spk_txout;
8
9/// Utilities for indexing transaction data.
10///
11/// Types which implement this trait can be used to construct an [`IndexedTxGraph`].
12/// This trait's methods should rarely be called directly.
13///
14/// [`IndexedTxGraph`]: crate::IndexedTxGraph
15pub trait Indexer {
16 /// The resultant "changeset" when new transaction data is indexed.
17 type ChangeSet;
18
19 /// Scan and index the given `outpoint` and `txout`.
20 fn index_txout(&mut self, outpoint: OutPoint, txout: &TxOut) -> Self::ChangeSet;
21
22 /// Scans a transaction for relevant outpoints, which are stored and indexed internally.
23 fn index_tx(&mut self, tx: &Transaction) -> Self::ChangeSet;
24
25 /// Apply changeset to itself.
26 fn apply_changeset(&mut self, changeset: Self::ChangeSet);
27
28 /// Determines the [`ChangeSet`](Indexer::ChangeSet) between `self` and an empty [`Indexer`].
29 fn initial_changeset(&self) -> Self::ChangeSet;
30
31 /// Determines whether the transaction should be included in the index.
32 fn is_tx_relevant(&self, tx: &Transaction) -> bool;
33}