reth_payload_primitives/
payload.rs1use crate::{MessageValidationKind, PayloadAttributes};
2use alloy_eips::eip4895::Withdrawal;
3use alloy_primitives::B256;
4use alloy_rpc_types_engine::ExecutionPayload;
5
6#[derive(Debug)]
10pub enum PayloadOrAttributes<'a, Attributes> {
11 ExecutionPayload {
13 payload: &'a ExecutionPayload,
15 parent_beacon_block_root: Option<B256>,
17 },
18 PayloadAttributes(&'a Attributes),
20}
21
22impl<'a, Attributes> PayloadOrAttributes<'a, Attributes> {
23 pub const fn from_execution_payload(
26 payload: &'a ExecutionPayload,
27 parent_beacon_block_root: Option<B256>,
28 ) -> Self {
29 Self::ExecutionPayload { payload, parent_beacon_block_root }
30 }
31
32 pub const fn from_attributes(attributes: &'a Attributes) -> Self {
34 Self::PayloadAttributes(attributes)
35 }
36}
37
38impl<Attributes> PayloadOrAttributes<'_, Attributes>
39where
40 Attributes: PayloadAttributes,
41{
42 pub fn withdrawals(&self) -> Option<&Vec<Withdrawal>> {
44 match self {
45 Self::ExecutionPayload { payload, .. } => payload.withdrawals(),
46 Self::PayloadAttributes(attributes) => attributes.withdrawals(),
47 }
48 }
49
50 pub fn timestamp(&self) -> u64 {
52 match self {
53 Self::ExecutionPayload { payload, .. } => payload.timestamp(),
54 Self::PayloadAttributes(attributes) => attributes.timestamp(),
55 }
56 }
57
58 pub fn parent_beacon_block_root(&self) -> Option<B256> {
60 match self {
61 Self::ExecutionPayload { parent_beacon_block_root, .. } => *parent_beacon_block_root,
62 Self::PayloadAttributes(attributes) => attributes.parent_beacon_block_root(),
63 }
64 }
65
66 pub const fn message_validation_kind(&self) -> MessageValidationKind {
68 match self {
69 Self::ExecutionPayload { .. } => MessageValidationKind::Payload,
70 Self::PayloadAttributes(_) => MessageValidationKind::PayloadAttributes,
71 }
72 }
73}
74
75impl<'a, AttributesType> From<&'a AttributesType> for PayloadOrAttributes<'a, AttributesType>
76where
77 AttributesType: PayloadAttributes,
78{
79 fn from(attributes: &'a AttributesType) -> Self {
80 Self::PayloadAttributes(attributes)
81 }
82}