Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add additional payloadbody conversion fn #1989

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is breaking

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, these were just introduced, dont believe anyone's using that besides us

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