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 tryfrom payload for block #1854

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
17 changes: 17 additions & 0 deletions crates/rpc-types-engine/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,15 @@ pub enum ExecutionPayload {
}

impl ExecutionPayload {
/// Converts [`ExecutionPayloadV1`] to [`Block`]
pub fn try_into_block<T: Decodable2718>(self) -> Result<Block<T>, PayloadError> {
match self {
Self::V1(payload) => payload.try_into_block(),
Self::V2(payload) => payload.try_into_block(),
Self::V3(payload) => payload.try_into_block(),
}
}

/// Returns a reference to the V1 payload.
pub const fn as_v1(&self) -> &ExecutionPayloadV1 {
match self {
Expand Down Expand Up @@ -767,6 +776,14 @@ impl From<ExecutionPayloadV3> for ExecutionPayload {
}
}

impl<T: Decodable2718> TryFrom<ExecutionPayload> for Block<T> {
type Error = PayloadError;

fn try_from(value: ExecutionPayload) -> Result<Self, Self::Error> {
value.try_into_block()
}
}

// Deserializes untagged ExecutionPayload by trying each variant in falling order
#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for ExecutionPayload {
Expand Down
Loading