chore: touchups PayloadOrAttributes (#11749)

This commit is contained in:
Matthias Seitz
2024-10-15 17:47:04 +02:00
committed by GitHub
parent 5aceb3e11e
commit 04f5b53462

View File

@@ -3,8 +3,10 @@ use alloy_primitives::B256;
use alloy_rpc_types::engine::ExecutionPayload;
/// Either an [`ExecutionPayload`] or a types that implements the [`PayloadAttributes`] trait.
///
/// This is a helper type to unify pre-validation of version specific fields of the engine API.
#[derive(Debug)]
pub enum PayloadOrAttributes<'a, AttributesType> {
pub enum PayloadOrAttributes<'a, Attributes> {
/// An [`ExecutionPayload`] and optional parent beacon block root.
ExecutionPayload {
/// The inner execution payload
@@ -13,13 +15,10 @@ pub enum PayloadOrAttributes<'a, AttributesType> {
parent_beacon_block_root: Option<B256>,
},
/// A payload attributes type.
PayloadAttributes(&'a AttributesType),
PayloadAttributes(&'a Attributes),
}
impl<'a, AttributesType> PayloadOrAttributes<'a, AttributesType>
where
AttributesType: PayloadAttributes,
{
impl<'a, Attributes> PayloadOrAttributes<'a, Attributes> {
/// Construct a [`PayloadOrAttributes`] from an [`ExecutionPayload`] and optional parent beacon
/// block root.
pub const fn from_execution_payload(
@@ -29,6 +28,16 @@ where
Self::ExecutionPayload { payload, parent_beacon_block_root }
}
/// Construct a [`PayloadOrAttributes::PayloadAttributes`] variant
pub const fn from_attributes(attributes: &'a Attributes) -> Self {
Self::PayloadAttributes(attributes)
}
}
impl<Attributes> PayloadOrAttributes<'_, Attributes>
where
Attributes: PayloadAttributes,
{
/// Return the withdrawals for the payload or attributes.
pub fn withdrawals(&self) -> Option<&Vec<alloy_rpc_types::Withdrawal>> {
match self {