Skip to content

Commit

Permalink
feat: implement default index_tx method
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimirfomene committed Oct 13, 2023
1 parent 3569acc commit 585986c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
cargo update -p rustls:0.20.9 --precise "0.20.8"
cargo update -p tokio:1.33.0 --precise "1.29.1"
cargo update -p tokio-util --precise "0.7.8"
cargo update -p flate2:1.0.27 --precise "1.0.26"
cargo update -p flate2:1.0.28 --precise "1.0.26"
cargo update -p reqwest --precise "0.11.18"
cargo update -p h2 --precise "0.3.20"
cargo update -p rustls-webpki:0.100.3 --precise "0.100.1"
Expand Down
10 changes: 8 additions & 2 deletions crates/chain/src/indexed_tx_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,19 @@ impl<A, K> From<keychain::ChangeSet<K>> for ChangeSet<A, keychain::ChangeSet<K>>
/// This trait's methods should rarely be called directly.
pub trait Indexer {
/// The resultant "changeset" when new transaction data is indexed.
type ChangeSet;
type ChangeSet: Append + Default;

/// Scan and index the given `outpoint` and `txout`.
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 {
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);
Expand Down
8 changes: 0 additions & 8 deletions crates/chain/src/keychain/txout_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ impl<K: Clone + Ord + Debug> Indexer for KeychainTxOutIndex<K> {
}
}

fn index_tx(&mut self, tx: &bitcoin::Transaction) -> Self::ChangeSet {
let mut changeset = super::ChangeSet::<K>::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())
}
Expand Down

0 comments on commit 585986c

Please sign in to comment.