Skip to content

Commit

Permalink
sidecar
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Oct 31, 2024
1 parent a44eeef commit 55ac6ae
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions crates/rpc-types-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ extern crate alloc;

mod cancun;
pub use cancun::*;
mod prague;
pub use prague::*;
mod sidecar;
pub use sidecar::*;

Expand Down
28 changes: 20 additions & 8 deletions crates/rpc-types-engine/src/sidecar.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Contains helpers for dealing with additional parameters of `newPayload` requests.

use crate::{CancunPayloadFields, MaybeCancunPayloadFields};
use crate::{
CancunPayloadFields, MaybeCancunPayloadFields, MaybePraguePayloadFields, PraguePayloadFields,
};
use alloc::vec::Vec;
use alloy_eips::eip7685::Requests;
use alloy_primitives::B256;
Expand All @@ -15,30 +17,35 @@ pub struct ExecutionPayloadSidecar {
cancun: MaybeCancunPayloadFields,
/// The EIP-7685 requests provided as additional request params to `engine_newPayloadV4` that
/// are not present in the `ExecutionPayload`.
prague: Option<Requests>,
prague: MaybePraguePayloadFields,
}

impl ExecutionPayloadSidecar {
/// Returns a new empty instance (pre-cancun, v1, v2)
pub const fn none() -> Self {
Self { cancun: MaybeCancunPayloadFields::none(), prague: None }
Self { cancun: MaybeCancunPayloadFields::none(), prague: MaybePraguePayloadFields::none() }
}

/// Creates a new instance for cancun with the cancun fields for `engine_newPayloadV3`
pub fn v3(cancun: CancunPayloadFields) -> Self {
Self { cancun: cancun.into(), prague: None }
Self { cancun: cancun.into(), prague: MaybePraguePayloadFields::none() }
}

/// Creates a new instance post prague for `engine_newPayloadV4`
pub fn v4(cancun: CancunPayloadFields, requests: Requests) -> Self {
Self { cancun: cancun.into(), prague: Some(requests) }
pub fn v4(cancun: CancunPayloadFields, prague: PraguePayloadFields) -> Self {
Self { cancun: cancun.into(), prague: prague.into() }
}

/// Returns a reference to the [`CancunPayloadFields`].
pub const fn cancun(&self) -> Option<&CancunPayloadFields> {
self.cancun.as_ref()
}

/// Returns a reference to the [`PraguePayloadFields`].
pub const fn prague(&self) -> Option<&PraguePayloadFields> {
self.prague.as_ref()
}

/// Returns the parent beacon block root, if any.
pub fn parent_beacon_block_root(&self) -> Option<B256> {
self.cancun.parent_beacon_block_root()
Expand All @@ -50,7 +57,12 @@ impl ExecutionPayloadSidecar {
}

/// Returns the EIP-7685 requests
pub const fn requests(&self) -> Option<&Requests> {
self.prague.as_ref()
pub fn requests(&self) -> Option<&Requests> {
self.prague.requests()
}

/// Returns the target blobs per block
pub fn target_blobs_per_block(&self) -> Option<u64> {
self.prague.target_blobs_per_block()
}
}

0 comments on commit 55ac6ae

Please sign in to comment.