From 231e2bb17af4308cd4baa66db535e7e82e82efb5 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 1 Feb 2025 12:48:08 +0100 Subject: [PATCH] feat: add additional payloadbody conversion fn --- crates/rpc-types-engine/src/payload.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/crates/rpc-types-engine/src/payload.rs b/crates/rpc-types-engine/src/payload.rs index 68b5a6d9969..3efc968476d 100644 --- a/crates/rpc-types-engine/src/payload.rs +++ b/crates/rpc-types-engine/src/payload.rs @@ -1080,18 +1080,29 @@ pub struct ExecutionPayloadBodyV1 { } impl ExecutionPayloadBodyV1 { - /// Converts a [`alloy_consensus::Block`] into an execution payload body. - pub fn from_block(block: Block) -> Self { + /// Creates an [`ExecutionPayloadBodyV1`] from the given withdrawals and transactions + pub fn new<'a, T>( + withdrawals: Option, + transactions: impl IntoIterator, + ) -> Self + where + T: Encodable2718 + 'a, + { Self { - transactions: block.body.transactions().map(|tx| tx.encoded_2718().into()).collect(), - withdrawals: block.body.withdrawals.map(Withdrawals::into_inner), + transactions: transactions.into_iter().map(|tx| tx.encoded_2718().into()).collect(), + withdrawals: withdrawals.map(Withdrawals::into_inner), } } + + /// Converts a [`alloy_consensus::Block`] into an execution payload body. + pub fn from_block(block: &Block) -> Self { + Self::new(block.body.withdrawals.clone(), block.body.transactions()) + } } impl From> for ExecutionPayloadBodyV1 { fn from(value: Block) -> Self { - Self::from_block(value) + Self::from_block(&value) } }