Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add helper iter for tx hashes #13638

Merged
merged 1 commit into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading