/// with `prev_blockhash` and `height-1` as the `connected_to` parameter.
///
/// [`apply_block_connected_to`]: Self::apply_block_connected_to
- pub fn apply_block(&mut self, block: Block, height: u32) -> Result<(), CannotConnectError>
+ pub fn apply_block(&mut self, block: &Block, height: u32) -> Result<(), CannotConnectError>
where
D: PersistBackend<ChangeSet>,
{
/// internal [`TxGraph`].
pub fn apply_block_connected_to(
&mut self,
- block: Block,
+ block: &Block,
height: u32,
connected_to: BlockId,
) -> Result<(), ApplyHeaderError>
tip: emission.checkpoint,
introduce_older_blocks: false,
})?;
- let indexed_additions = indexed_tx_graph.apply_block_relevant(emission.block, height);
+ let indexed_additions = indexed_tx_graph.apply_block_relevant(&emission.block, height);
assert!(indexed_additions.is_empty());
}
tip: emission.checkpoint,
introduce_older_blocks: false,
})?;
- let indexed_additions = indexed_tx_graph.apply_block_relevant(emission.block, height);
+ let indexed_additions = indexed_tx_graph.apply_block_relevant(&emission.block, height);
assert!(indexed_additions.graph.txs.is_empty());
assert!(indexed_additions.graph.txouts.is_empty());
assert_eq!(indexed_additions.graph.anchors, exp_anchors);
/// Irrelevant transactions in `txs` will be ignored.
pub fn apply_block_relevant(
&mut self,
- block: Block,
+ block: &Block,
height: u32,
) -> ChangeSet<A, I::ChangeSet> {
let block_id = BlockId {
hash: block.block_hash(),
height,
};
- let txs = block.txdata.iter().enumerate().map(|(tx_pos, tx)| {
- (
- tx,
- core::iter::once(A::from_block_position(&block, block_id, tx_pos)),
- )
- });
- self.batch_insert_relevant(txs)
+ let mut changeset = ChangeSet::<A, I::ChangeSet>::default();
+ for (tx_pos, tx) in block.txdata.iter().enumerate() {
+ changeset.indexer.append(self.index.index_tx(tx));
+ if self.index.is_tx_relevant(tx) {
+ let txid = tx.txid();
+ let anchor = A::from_block_position(block, block_id, tx_pos);
+ changeset.graph.append(self.graph.insert_tx(tx.clone()));
+ changeset
+ .graph
+ .append(self.graph.insert_anchor(txid, anchor));
+ }
+ }
+ changeset
}
/// Batch insert all transactions of the given `block` of `height`.