reth_payload_primitives/
traits.rs1use alloc::vec::Vec;
2use alloy_eips::{
3 eip4895::{Withdrawal, Withdrawals},
4 eip7685::Requests,
5};
6use alloy_primitives::{Address, B256, U256};
7use alloy_rpc_types_engine::{PayloadAttributes as EthPayloadAttributes, PayloadId};
8use core::fmt;
9use reth_chain_state::ExecutedBlockWithTrieUpdates;
10use reth_primitives_traits::{NodePrimitives, SealedBlock};
11
12#[auto_impl::auto_impl(&, Arc)]
15pub trait BuiltPayload: Send + Sync + fmt::Debug {
16 type Primitives: NodePrimitives;
18
19 fn block(&self) -> &SealedBlock<<Self::Primitives as NodePrimitives>::Block>;
21
22 fn fees(&self) -> U256;
24
25 fn executed_block(&self) -> Option<ExecutedBlockWithTrieUpdates<Self::Primitives>> {
27 None
28 }
29
30 fn requests(&self) -> Option<Requests>;
32}
33
34pub trait PayloadBuilderAttributes: Send + Sync + fmt::Debug {
39 type RpcPayloadAttributes;
42 type Error: core::error::Error;
44
45 fn try_new(
49 parent: B256,
50 rpc_payload_attributes: Self::RpcPayloadAttributes,
51 version: u8,
52 ) -> Result<Self, Self::Error>
53 where
54 Self: Sized;
55
56 fn payload_id(&self) -> PayloadId;
58
59 fn parent(&self) -> B256;
61
62 fn timestamp(&self) -> u64;
64
65 fn parent_beacon_block_root(&self) -> Option<B256>;
67
68 fn suggested_fee_recipient(&self) -> Address;
70
71 fn prev_randao(&self) -> B256;
73
74 fn withdrawals(&self) -> &Withdrawals;
76}
77
78pub trait PayloadAttributes:
83 serde::de::DeserializeOwned + serde::Serialize + fmt::Debug + Clone + Send + Sync + 'static
84{
85 fn timestamp(&self) -> u64;
87
88 fn withdrawals(&self) -> Option<&Vec<Withdrawal>>;
90
91 fn parent_beacon_block_root(&self) -> Option<B256>;
93}
94
95impl PayloadAttributes for EthPayloadAttributes {
96 fn timestamp(&self) -> u64 {
97 self.timestamp
98 }
99
100 fn withdrawals(&self) -> Option<&Vec<Withdrawal>> {
101 self.withdrawals.as_ref()
102 }
103
104 fn parent_beacon_block_root(&self) -> Option<B256> {
105 self.parent_beacon_block_root
106 }
107}
108
109#[cfg(feature = "op")]
110impl PayloadAttributes for op_alloy_rpc_types_engine::OpPayloadAttributes {
111 fn timestamp(&self) -> u64 {
112 self.payload_attributes.timestamp
113 }
114
115 fn withdrawals(&self) -> Option<&Vec<Withdrawal>> {
116 self.payload_attributes.withdrawals.as_ref()
117 }
118
119 fn parent_beacon_block_root(&self) -> Option<B256> {
120 self.payload_attributes.parent_beacon_block_root
121 }
122}
123
124pub trait PayloadAttributesBuilder<Attributes>: Send + Sync + 'static {
126 fn build(&self, timestamp: u64) -> Attributes;
128}