Skip to content

Commit

Permalink
feat: add additional payloadbody conversion fn (#1989)
Browse files Browse the repository at this point in the history
* feat: add additional payloadbody conversion fn

* make non breaking
  • Loading branch information
mattsse authored Feb 3, 2025
1 parent 10164e9 commit 0fbc37d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions crates/rpc-types-engine/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,13 +1088,24 @@ 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 {
Expand Down

0 comments on commit 0fbc37d

Please sign in to comment.