From e28c6e8bb65bd1000c5d19760055485f85d3e597 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 3 Jan 2025 21:15:04 +0100 Subject: [PATCH] feat: add helper iter for tx hashes --- crates/primitives-traits/src/block/body.rs | 5 +++++ crates/rpc/rpc-types-compat/src/block.rs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/primitives-traits/src/block/body.rs b/crates/primitives-traits/src/block/body.rs index f1f83d46e280..a68aaa0157b6 100644 --- a/crates/primitives-traits/src/block/body.rs +++ b/crates/primitives-traits/src/block/body.rs @@ -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 + '_ { + self.transactions().iter().map(|tx| tx.tx_hash()) + } + /// Consume the block body and return a [`Vec`] of transactions. fn into_transactions(self) -> Vec; diff --git a/crates/rpc/rpc-types-compat/src/block.rs b/crates/rpc/rpc-types-compat/src/block.rs index 7d8c1480033a..8d18d110ba15 100644 --- a/crates/rpc/rpc-types-compat/src/block.rs +++ b/crates/rpc/rpc-types-compat/src/block.rs @@ -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(),