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: impl From for exec payload v4 #695

Merged
merged 1 commit into from
May 6, 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
25 changes: 25 additions & 0 deletions crates/rpc-types-engine/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ pub enum ExecutionPayload {
V2(ExecutionPayloadV2),
/// V3 payload
V3(ExecutionPayloadV3),
/// V4 payload
V4(ExecutionPayloadV4),
}

impl ExecutionPayload {
Expand All @@ -580,6 +582,7 @@ impl ExecutionPayload {
ExecutionPayload::V1(payload) => payload,
ExecutionPayload::V2(payload) => &payload.payload_inner,
ExecutionPayload::V3(payload) => &payload.payload_inner.payload_inner,
ExecutionPayload::V4(payload) => &payload.payload_inner.payload_inner.payload_inner,
}
}

Expand All @@ -589,6 +592,7 @@ impl ExecutionPayload {
ExecutionPayload::V1(payload) => payload,
ExecutionPayload::V2(payload) => &mut payload.payload_inner,
ExecutionPayload::V3(payload) => &mut payload.payload_inner.payload_inner,
ExecutionPayload::V4(payload) => &mut payload.payload_inner.payload_inner.payload_inner,
}
}

Expand All @@ -598,6 +602,7 @@ impl ExecutionPayload {
ExecutionPayload::V1(payload) => payload,
ExecutionPayload::V2(payload) => payload.payload_inner,
ExecutionPayload::V3(payload) => payload.payload_inner.payload_inner,
ExecutionPayload::V4(payload) => payload.payload_inner.payload_inner.payload_inner,
}
}

Expand All @@ -607,6 +612,7 @@ impl ExecutionPayload {
ExecutionPayload::V1(_) => None,
ExecutionPayload::V2(payload) => Some(payload),
ExecutionPayload::V3(payload) => Some(&payload.payload_inner),
ExecutionPayload::V4(payload) => Some(&payload.payload_inner.payload_inner),
}
}

Expand All @@ -616,6 +622,7 @@ impl ExecutionPayload {
ExecutionPayload::V1(_) => None,
ExecutionPayload::V2(payload) => Some(payload),
ExecutionPayload::V3(payload) => Some(&mut payload.payload_inner),
ExecutionPayload::V4(payload) => Some(&mut payload.payload_inner.payload_inner),
}
}

Expand All @@ -624,6 +631,7 @@ impl ExecutionPayload {
match self {
ExecutionPayload::V1(_) | ExecutionPayload::V2(_) => None,
ExecutionPayload::V3(payload) => Some(payload),
ExecutionPayload::V4(payload) => Some(&payload.payload_inner),
}
}

Expand All @@ -632,6 +640,23 @@ impl ExecutionPayload {
match self {
ExecutionPayload::V1(_) | ExecutionPayload::V2(_) => None,
ExecutionPayload::V3(payload) => Some(payload),
ExecutionPayload::V4(payload) => Some(&mut payload.payload_inner),
}
}

/// Returns a reference to the V4 payload, if any.
pub const fn as_v4(&self) -> Option<&ExecutionPayloadV4> {
match self {
ExecutionPayload::V1(_) | ExecutionPayload::V2(_) | ExecutionPayload::V3(_) => None,
ExecutionPayload::V4(payload) => Some(payload),
}
}

/// Returns a mutable reference to the V4 payload, if any.
pub fn as_v4_mut(&mut self) -> Option<&mut ExecutionPayloadV4> {
match self {
ExecutionPayload::V1(_) | ExecutionPayload::V2(_) | ExecutionPayload::V3(_) => None,
ExecutionPayload::V4(payload) => Some(payload),
}
}

Expand Down
Loading