[bdk_chain_redesign] Modify signature of TxIndex
This makes the API of `TxIndex` more consistent between scanning in data and checking whether certain data is relevant.
This commit is contained in:
parent
da4cef044d
commit
ddd5e951f5
@ -261,7 +261,7 @@ impl<A: BlockAnchor, I: TxIndex> IndexedTxGraph<A, I> {
|
|||||||
{
|
{
|
||||||
self.graph
|
self.graph
|
||||||
.all_txouts()
|
.all_txouts()
|
||||||
.filter(|(_, txo)| self.index.is_spk_owned(&txo.script_pubkey))
|
.filter(|&(op, txo)| self.index.is_txout_relevant(op, txo))
|
||||||
.filter_map(move |(op, txout)| -> Option<Result<_, C::Error>> {
|
.filter_map(move |(op, txout)| -> Option<Result<_, C::Error>> {
|
||||||
let graph_tx = self.graph.get_tx(op.txid)?;
|
let graph_tx = self.graph.get_tx(op.txid)?;
|
||||||
|
|
||||||
|
@ -105,12 +105,12 @@ impl<K: Clone + Ord + Debug + 'static> TxIndex for KeychainTxOutIndex<K> {
|
|||||||
self.apply_additions(additions)
|
self.apply_additions(additions)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_tx_relevant(&self, tx: &bitcoin::Transaction) -> bool {
|
fn is_txout_relevant(&self, _outpoint: OutPoint, txout: &TxOut) -> bool {
|
||||||
self.is_relevant(tx)
|
self.index_of_spk(&txout.script_pubkey).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_spk_owned(&self, spk: &Script) -> bool {
|
fn is_tx_relevant(&self, tx: &bitcoin::Transaction) -> bool {
|
||||||
self.index_of_spk(spk).is_some()
|
self.is_relevant(tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,12 +69,12 @@ impl<I: Clone + Ord + 'static> TxIndex for SpkTxOutIndex<I> {
|
|||||||
// This applies nothing.
|
// This applies nothing.
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_tx_relevant(&self, tx: &Transaction) -> bool {
|
fn is_txout_relevant(&self, _outpoint: OutPoint, txout: &TxOut) -> bool {
|
||||||
self.is_relevant(tx)
|
self.index_of_spk(&txout.script_pubkey).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_spk_owned(&self, spk: &Script) -> bool {
|
fn is_tx_relevant(&self, tx: &Transaction) -> bool {
|
||||||
self.index_of_spk(spk).is_some()
|
self.is_relevant(tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use bitcoin::{Block, BlockHash, OutPoint, Script, Transaction, TxOut};
|
use bitcoin::{Block, BlockHash, OutPoint, Transaction, TxOut};
|
||||||
|
|
||||||
use crate::BlockId;
|
use crate::BlockId;
|
||||||
|
|
||||||
@ -80,10 +80,9 @@ pub trait TxIndex {
|
|||||||
/// Apply additions to itself.
|
/// Apply additions to itself.
|
||||||
fn apply_additions(&mut self, additions: Self::Additions);
|
fn apply_additions(&mut self, additions: Self::Additions);
|
||||||
|
|
||||||
/// A transaction is relevant if it contains a txout with a script_pubkey that we own, or if it
|
/// Returns whether the txout is marked as relevant in the index.
|
||||||
/// spends an already-indexed outpoint that we have previously indexed.
|
fn is_txout_relevant(&self, outpoint: OutPoint, txout: &TxOut) -> bool;
|
||||||
fn is_tx_relevant(&self, tx: &Transaction) -> bool;
|
|
||||||
|
|
||||||
/// Returns whether the script pubkey is owned by us.
|
/// Returns whether the transaction is marked as relevant in the index.
|
||||||
fn is_spk_owned(&self, spk: &Script) -> bool;
|
fn is_tx_relevant(&self, tx: &Transaction) -> bool;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
//! # use bitcoin::Transaction;
|
//! # use bitcoin::Transaction;
|
||||||
//! # let tx_a = tx_from_hex(RAW_TX_1);
|
//! # let tx_a = tx_from_hex(RAW_TX_1);
|
||||||
//! # let tx_b = tx_from_hex(RAW_TX_2);
|
//! # let tx_b = tx_from_hex(RAW_TX_2);
|
||||||
//! let mut graph = TxGraph::<BlockId>::default();
|
//! let mut graph: TxGraph = TxGraph::default();
|
||||||
//! let update = TxGraph::new(vec![tx_a, tx_b]);
|
//! let update = TxGraph::new(vec![tx_a, tx_b]);
|
||||||
//!
|
//!
|
||||||
//! // preview additions as the result of the update
|
//! // preview additions as the result of the update
|
||||||
|
Loading…
x
Reference in New Issue
Block a user