Skip to content

Commit

Permalink
feat: add tryfrom payload for block
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Dec 27, 2024
1 parent ccfb974 commit e7dec6e
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit e7dec6e

Please sign in to comment.