From 7b826ac7a76cf6a2552117ac0d10c0875ef9e8c8 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 17 Nov 2023 11:13:38 +0100 Subject: [PATCH] chore: add missing helper fns --- crates/primitives/src/block.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index 2d820734d50d..a432cdbc2089 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -102,6 +102,34 @@ impl BlockWithSenders { pub fn into_components(self) -> (Block, Vec
) { (self.block, self.senders) } + + /// Returns an iterator over all transactions in the block. + #[inline] + pub fn transactions(&self) -> impl Iterator + '_ { + self.block.body.iter() + } + + /// Returns an iterator over all transactions and their sender. + #[inline] + pub fn transactions_with_sender( + &self, + ) -> impl Iterator + '_ { + self.senders.iter().zip(self.block.body.iter()) + } + + /// Consumes the block and returns the transactions of the block. + #[inline] + pub fn into_transactions(self) -> Vec { + self.block.body + } + + /// Returns an iterator over all transactions in the chain. + #[inline] + pub fn into_transactions_ecrecovered( + self, + ) -> impl Iterator { + self.block.body.into_iter().zip(self.senders).map(|(tx, sender)| tx.with_signer(sender)) + } } impl Deref for BlockWithSenders {