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(eips): Make prague field an enum #1574

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
24 changes: 24 additions & 0 deletions crates/eips/src/eip7685.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,30 @@ impl Requests {
}
}

/// A list of requests or a precomputed requests hash.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PragueRequests {
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
/// Stores a list of requests for dynamic requests hash calculation.
Requests(Requests),
/// Stores a precomputed requests hash.
Hash(B256),
}

impl PragueRequests {
/// Returns the requests hash for the enum instance.
///
/// - If the instance contains a list of requests, this function calculates the hash using
/// `requests_hash` of the [`Requests`] struct.
/// - If it contains a precomputed hash, it returns that hash directly.
#[cfg(feature = "sha2")]
pub fn requests_hash(&self) -> B256 {
match self {
Self::Requests(requests) => requests.requests_hash(),
Self::Hash(precomputed_hash) => *precomputed_hash,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
Expand Down
12 changes: 8 additions & 4 deletions crates/rpc-types-engine/src/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{CancunPayloadFields, MaybeCancunPayloadFields};
use alloc::vec::Vec;
use alloy_eips::eip7685::Requests;
use alloy_eips::eip7685::{PragueRequests, Requests};
use alloy_primitives::B256;

/// Container type for all available additional `newPayload` request parameters that are not present
Expand All @@ -15,7 +15,7 @@ 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: Option<PragueRequests>,
}

impl ExecutionPayloadSidecar {
Expand All @@ -30,7 +30,7 @@ impl ExecutionPayloadSidecar {
}

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

Expand All @@ -51,6 +51,10 @@ impl ExecutionPayloadSidecar {

/// Returns the EIP-7685 requests
pub const fn requests(&self) -> Option<&Requests> {
self.prague.as_ref()
if let Some(PragueRequests::Requests(ref requests)) = self.prague {
DoTheBestToGetTheBest marked this conversation as resolved.
Show resolved Hide resolved
Some(requests)
} else {
None
}
}
}