reth_payload_primitives/
payload.rsuse crate::{MessageValidationKind, PayloadAttributes};
use alloy_primitives::B256;
use alloy_rpc_types::engine::ExecutionPayload;
#[derive(Debug)]
pub enum PayloadOrAttributes<'a, AttributesType> {
ExecutionPayload {
payload: &'a ExecutionPayload,
parent_beacon_block_root: Option<B256>,
},
PayloadAttributes(&'a AttributesType),
}
impl<'a, AttributesType> PayloadOrAttributes<'a, AttributesType>
where
AttributesType: PayloadAttributes,
{
pub const fn from_execution_payload(
payload: &'a ExecutionPayload,
parent_beacon_block_root: Option<B256>,
) -> Self {
Self::ExecutionPayload { payload, parent_beacon_block_root }
}
pub fn withdrawals(&self) -> Option<&Vec<alloy_rpc_types::Withdrawal>> {
match self {
Self::ExecutionPayload { payload, .. } => payload.withdrawals(),
Self::PayloadAttributes(attributes) => attributes.withdrawals(),
}
}
pub fn timestamp(&self) -> u64 {
match self {
Self::ExecutionPayload { payload, .. } => payload.timestamp(),
Self::PayloadAttributes(attributes) => attributes.timestamp(),
}
}
pub fn parent_beacon_block_root(&self) -> Option<B256> {
match self {
Self::ExecutionPayload { parent_beacon_block_root, .. } => *parent_beacon_block_root,
Self::PayloadAttributes(attributes) => attributes.parent_beacon_block_root(),
}
}
pub const fn message_validation_kind(&self) -> MessageValidationKind {
match self {
Self::ExecutionPayload { .. } => MessageValidationKind::Payload,
Self::PayloadAttributes(_) => MessageValidationKind::PayloadAttributes,
}
}
}
impl<'a, AttributesType> From<&'a AttributesType> for PayloadOrAttributes<'a, AttributesType>
where
AttributesType: PayloadAttributes,
{
fn from(attributes: &'a AttributesType) -> Self {
Self::PayloadAttributes(attributes)
}
}