diff --git a/crates/chain/src/indexed_tx_graph.rs b/crates/chain/src/indexed_tx_graph.rs index c2b83600b..bf3e541b5 100644 --- a/crates/chain/src/indexed_tx_graph.rs +++ b/crates/chain/src/indexed_tx_graph.rs @@ -44,6 +44,18 @@ impl IndexedTxGraph { } impl IndexedTxGraph { + /// Determines the [`ChangeSet`] between `self` and an empty [`IndexedTxGraph`]. + pub fn initial_changeset(&self) -> ChangeSet { + let graph = self.graph.initial_changeset(); + let indexer = self.index.initial_changeset(); + ChangeSet { graph, indexer } + } +} + +impl IndexedTxGraph +where + I::ChangeSet: Default + Append, +{ /// Applies the [`ChangeSet`] to the [`IndexedTxGraph`]. pub fn apply_changeset(&mut self, changeset: ChangeSet) { self.index.apply_changeset(changeset.indexer); @@ -58,18 +70,6 @@ impl IndexedTxGraph { self.graph.apply_changeset(changeset.graph); } - /// Determines the [`ChangeSet`] between `self` and an empty [`IndexedTxGraph`]. - pub fn initial_changeset(&self) -> ChangeSet { - let graph = self.graph.initial_changeset(); - let indexer = self.index.initial_changeset(); - ChangeSet { graph, indexer } - } -} - -impl IndexedTxGraph -where - I::ChangeSet: Default + Append, -{ fn index_tx_graph_changeset( &mut self, tx_graph_changeset: &tx_graph::ChangeSet, @@ -341,7 +341,16 @@ pub trait Indexer { fn index_txout(&mut self, outpoint: OutPoint, txout: &TxOut) -> Self::ChangeSet; /// Scans a transaction for relevant outpoints, which are stored and indexed internally. - fn index_tx(&mut self, tx: &Transaction) -> Self::ChangeSet; + fn index_tx(&mut self, tx: &Transaction) -> Self::ChangeSet + where + Self::ChangeSet: Default + Append, + { + let mut changeset = Self::ChangeSet::default(); + for (op, txout) in tx.output.iter().enumerate() { + changeset.append(self.index_txout(OutPoint::new(tx.txid(), op as u32), txout)); + } + changeset + } /// Apply changeset to itself. fn apply_changeset(&mut self, changeset: Self::ChangeSet); diff --git a/crates/chain/src/keychain/txout_index.rs b/crates/chain/src/keychain/txout_index.rs index da6a1e25b..efd9acd0e 100644 --- a/crates/chain/src/keychain/txout_index.rs +++ b/crates/chain/src/keychain/txout_index.rs @@ -126,14 +126,6 @@ impl Indexer for KeychainTxOutIndex { } } - fn index_tx(&mut self, tx: &bitcoin::Transaction) -> Self::ChangeSet { - let mut changeset = super::ChangeSet::::default(); - for (op, txout) in tx.output.iter().enumerate() { - changeset.append(self.index_txout(OutPoint::new(tx.txid(), op as u32), txout)); - } - changeset - } - fn initial_changeset(&self) -> Self::ChangeSet { super::ChangeSet(self.last_revealed.clone()) }