Skip to content

Commit

Permalink
feat: add helper iter for tx hashes (#13638)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jan 4, 2025
1 parent 9b44e2a commit 8befda5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions crates/primitives-traits/src/block/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ pub trait BlockBody:
/// Returns reference to transactions in block.
fn transactions(&self) -> &[Self::Transaction];

/// Returns an iterator over all transaction hashes in the block body.
fn transaction_hashes_iter(&self) -> impl Iterator<Item = &B256> + '_ {
self.transactions().iter().map(|tx| tx.tx_hash())
}

/// Consume the block body and return a [`Vec`] of transactions.
fn into_transactions(self) -> Vec<Self::Transaction>;

Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-types-compat/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ where
B: BlockTrait,
{
let block_hash = block_hash.unwrap_or_else(|| block.header().hash_slow());
let transactions = block.body().transactions().iter().map(|tx| *tx.tx_hash()).collect();
let transactions = block.body().transaction_hashes_iter().copied().collect();

from_block_with_transactions(
block.length(),
Expand Down

0 comments on commit 8befda5

Please sign in to comment.