Skip to content

Commit

Permalink
feat: add ExecutionPayloadSidecar type (alloy-rs#1517)
Browse files Browse the repository at this point in the history
* feat: add sidecar type

* feat: add ExecutionPayloadSidecar

* no-std

* clippy
  • Loading branch information
mattsse authored and lwedge99 committed Jan 3, 2025
1 parent b3bf5a7 commit bb78e43
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 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 sidecar;
pub use sidecar::*;

mod forkchoice;
pub use forkchoice::*;
Expand Down
55 changes: 55 additions & 0 deletions crates/rpc-types-engine/src/sidecar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//! Contains helpers for dealing with additional parameters of `newPayload` requests.
use crate::{CancunPayloadFields, MaybeCancunPayloadFields};
use alloc::vec::Vec;
use alloy_eips::eip7685::Requests;
use alloy_primitives::B256;

/// Container type for all available additional `newPayload` request parameters that are not present
/// in the `ExecutionPayload` object itself.
#[derive(Debug, Clone, Default)]
pub struct ExecutionPayloadSidecar {
/// Cancun request params introduced in `engine_newPayloadV3` that are not present in the
/// `ExecutionPayload`.
cancun: MaybeCancunPayloadFields,
/// The EIP-7685 requests provided as additional request params to `engine_newPayloadV4` that
/// are not present in the `ExecutionPayload`.
prague: Option<Requests>,
}

impl ExecutionPayloadSidecar {
/// Returns a new empty instance (pre-cancun, v1, v2)
pub const fn none() -> Self {
Self { cancun: MaybeCancunPayloadFields::none(), prague: 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 }
}

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

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

/// Returns the blob versioned hashes, if any.
pub fn versioned_hashes(&self) -> Option<&Vec<B256>> {
self.cancun.versioned_hashes()
}

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

0 comments on commit bb78e43

Please sign in to comment.