From 4ae727a1fb469beacee79fa8d3800152623961eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E5=AE=87?= Date: Wed, 3 May 2023 15:20:49 +0800 Subject: [PATCH] [chain_redesign] Relax generic constraints --- crates/chain/src/indexed_tx_graph.rs | 7 +++++-- crates/chain/src/keychain/txout_index.rs | 6 +++--- crates/chain/src/spk_txout_index.rs | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/chain/src/indexed_tx_graph.rs b/crates/chain/src/indexed_tx_graph.rs index 6d8c16ff..c550d86f 100644 --- a/crates/chain/src/indexed_tx_graph.rs +++ b/crates/chain/src/indexed_tx_graph.rs @@ -12,6 +12,7 @@ use crate::{ /// A struct that combines [`TxGraph`] and an [`Indexer`] implementation. /// /// This structure ensures that [`TxGraph`] and [`Indexer`] are updated atomically. +#[derive(Debug)] pub struct IndexedTxGraph { /// Transaction index. pub index: I, @@ -27,12 +28,14 @@ impl Default for IndexedTxGraph { } } -impl IndexedTxGraph { +impl IndexedTxGraph { /// Get a reference of the internal transaction graph. pub fn graph(&self) -> &TxGraph { &self.graph } +} +impl IndexedTxGraph { /// Applies the [`IndexedAdditions`] to the [`IndexedTxGraph`]. pub fn apply_additions(&mut self, additions: IndexedAdditions) { let IndexedAdditions { @@ -217,7 +220,7 @@ impl IndexedTxGraph { C: ChainOracle, F: FnMut(&Script) -> bool, { - let tip_height = chain_tip.anchor_block().height; + let tip_height = chain_tip.height; let mut immature = 0; let mut trusted_pending = 0; diff --git a/crates/chain/src/keychain/txout_index.rs b/crates/chain/src/keychain/txout_index.rs index f8ef46be..c7a8dd54 100644 --- a/crates/chain/src/keychain/txout_index.rs +++ b/crates/chain/src/keychain/txout_index.rs @@ -89,7 +89,7 @@ impl Deref for KeychainTxOutIndex { } } -impl Indexer for KeychainTxOutIndex { +impl Indexer for KeychainTxOutIndex { type Additions = DerivationAdditions; fn index_txout(&mut self, outpoint: OutPoint, txout: &TxOut) -> Self::Additions { @@ -109,9 +109,9 @@ impl Indexer for KeychainTxOutIndex { } } -impl OwnedIndexer for KeychainTxOutIndex { +impl OwnedIndexer for KeychainTxOutIndex { fn is_spk_owned(&self, spk: &Script) -> bool { - self.inner().is_spk_owned(spk) + self.index_of_spk(spk).is_some() } } diff --git a/crates/chain/src/spk_txout_index.rs b/crates/chain/src/spk_txout_index.rs index 9fdf3bc0..ae944149 100644 --- a/crates/chain/src/spk_txout_index.rs +++ b/crates/chain/src/spk_txout_index.rs @@ -53,7 +53,7 @@ impl Default for SpkTxOutIndex { } } -impl Indexer for SpkTxOutIndex { +impl Indexer for SpkTxOutIndex { type Additions = (); fn index_txout(&mut self, outpoint: OutPoint, txout: &TxOut) -> Self::Additions {