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

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Changes from 1 commit
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
Next Next commit
feat: add additional payloadbody conversion fn
mattsse committed Feb 1, 2025
commit 231e2bb17af4308cd4baa66db535e7e82e82efb5
21 changes: 16 additions & 5 deletions crates/rpc-types-engine/src/payload.rs
Original file line number Diff line number Diff line change
@@ -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

Copy link
Member Author

Choose a reason for hiding this comment

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

removed the breaking change, the recomended way would be the new fn anyway

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)
}
}