From 5d237fcc97376ac39eda031949f09156877bf952 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 6 Mar 2025 13:10:24 +0100 Subject: [PATCH] feat: add helper for eth body conversion (#14864) --- crates/primitives-traits/src/block/body.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/primitives-traits/src/block/body.rs b/crates/primitives-traits/src/block/body.rs index 53d20c5638..cd187d2f79 100644 --- a/crates/primitives-traits/src/block/body.rs +++ b/crates/primitives-traits/src/block/body.rs @@ -42,6 +42,19 @@ pub trait BlockBody: /// Returns reference to transactions in the block. fn transactions(&self) -> &[Self::Transaction]; + /// A Convenience function to convert this type into the regular ethereum block body that + /// consists of: + /// + /// - Transactions + /// - Withdrawals + /// - Ommers + /// + /// Note: This conversion can be incomplete. It is not expected that this `Body` is the same as + /// [`alloy_consensus::BlockBody`] only that it can be converted into it which is useful for + /// the `eth_` RPC namespace (e.g. RPC block). + fn into_ethereum_body(self) + -> alloy_consensus::BlockBody; + /// Returns an iterator over the transactions in the block. fn transactions_iter(&self) -> impl Iterator + '_ { self.transactions().iter() @@ -189,6 +202,10 @@ where &self.transactions } + fn into_ethereum_body(self) -> Self { + self + } + fn into_transactions(self) -> Vec { self.transactions }