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: misc payloadenvelopeinput conversions #1855

Merged
merged 1 commit into from
Dec 27, 2024
Merged
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
33 changes: 33 additions & 0 deletions crates/rpc-types-engine/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ pub struct ExecutionPayloadInputV2 {
pub withdrawals: Option<Vec<Withdrawal>>,
}

impl ExecutionPayloadInputV2 {
/// Converts [`ExecutionPayloadInputV2`] to [`ExecutionPayload`]
pub fn into_payload(self) -> ExecutionPayload {
match self.withdrawals {
Some(withdrawals) => ExecutionPayload::V2(ExecutionPayloadV2 {
payload_inner: self.execution_payload,
withdrawals,
}),
None => ExecutionPayload::V1(self.execution_payload),
}
}
}

impl From<ExecutionPayloadInputV2> for ExecutionPayload {
fn from(input: ExecutionPayloadInputV2) -> Self {
input.into_payload()
}
}

/// This structure maps for the return value of `engine_getPayload` of the beacon chain spec, for
/// V2.
///
Expand Down Expand Up @@ -299,6 +318,20 @@ impl ExecutionPayloadV2 {
self.payload_inner.timestamp
}

/// Converts [`ExecutionPayloadV2`] to [`ExecutionPayloadInputV2`].
///
/// An [`ExecutionPayloadInputV2`] should have a [`Some`] withdrawals field if shanghai is
/// active, otherwise the withdrawals field should be [`None`], so the `is_shanghai_active`
/// argument is provided which will either:
/// - include the withdrawals field as [`Some`] if true
/// - set the withdrawals field to [`None`] if false
pub fn into_payload_input_v2(self, is_shanghai_active: bool) -> ExecutionPayloadInputV2 {
ExecutionPayloadInputV2 {
execution_payload: self.payload_inner,
withdrawals: is_shanghai_active.then_some(self.withdrawals),
}
}

/// Converts [`ExecutionPayloadV2`] to [`Block`].
///
/// This performs the same conversion as the underlying V1 payload, but calculates the
Expand Down
Loading