Skip to content

Commit

Permalink
feat: add additional payloadbody conversion fn
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Feb 1, 2025
1 parent 1675da8 commit 231e2bb
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions crates/rpc-types-engine/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,18 +1080,29 @@ pub struct ExecutionPayloadBodyV1 {
}

impl ExecutionPayloadBodyV1 {
/// Converts a [`alloy_consensus::Block`] into an execution payload body.
pub fn from_block<T: Encodable2718, H>(block: Block<T, H>) -> Self {
/// Creates an [`ExecutionPayloadBodyV1`] from the given withdrawals and transactions
pub fn new<'a, T>(
withdrawals: Option<Withdrawals>,
transactions: impl IntoIterator<Item = &'a T>,
) -> 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<T: Encodable2718, H>(block: &Block<T, H>) -> Self {
Self::new(block.body.withdrawals.clone(), block.body.transactions())
}
}

impl<T: Encodable2718, H> From<Block<T, H>> for ExecutionPayloadBodyV1 {
fn from(value: Block<T, H>) -> Self {
Self::from_block(value)
Self::from_block(&value)
}
}

Expand Down

0 comments on commit 231e2bb

Please sign in to comment.