reth_payload_primitives/
traits.rs1use alloy_eips::{
2 eip4895::{Withdrawal, Withdrawals},
3 eip7685::Requests,
4};
5use alloy_primitives::{Address, B256, U256};
6use alloy_rpc_types_engine::{PayloadAttributes as EthPayloadAttributes, PayloadId};
7use reth_chain_state::ExecutedBlock;
8use reth_primitives::{EthPrimitives, NodePrimitives, SealedBlock};
9
10pub trait BuiltPayload<N: NodePrimitives = EthPrimitives>: Send + Sync + std::fmt::Debug {
13 fn block(&self) -> &SealedBlock<N::BlockHeader, N::BlockBody>;
15
16 fn fees(&self) -> U256;
18
19 fn executed_block(&self) -> Option<ExecutedBlock<N>> {
21 None
22 }
23
24 fn requests(&self) -> Option<Requests>;
26}
27
28pub trait PayloadBuilderAttributes: Send + Sync + std::fmt::Debug {
33 type RpcPayloadAttributes;
36 type Error: core::error::Error;
38
39 fn try_new(
43 parent: B256,
44 rpc_payload_attributes: Self::RpcPayloadAttributes,
45 version: u8,
46 ) -> Result<Self, Self::Error>
47 where
48 Self: Sized;
49
50 fn payload_id(&self) -> PayloadId;
52
53 fn parent(&self) -> B256;
55
56 fn timestamp(&self) -> u64;
58
59 fn parent_beacon_block_root(&self) -> Option<B256>;
61
62 fn suggested_fee_recipient(&self) -> Address;
64
65 fn prev_randao(&self) -> B256;
67
68 fn withdrawals(&self) -> &Withdrawals;
70}
71
72pub trait PayloadAttributes:
77 serde::de::DeserializeOwned + serde::Serialize + std::fmt::Debug + Clone + Send + Sync + 'static
78{
79 fn timestamp(&self) -> u64;
81
82 fn withdrawals(&self) -> Option<&Vec<Withdrawal>>;
84
85 fn parent_beacon_block_root(&self) -> Option<B256>;
87}
88
89impl PayloadAttributes for EthPayloadAttributes {
90 fn timestamp(&self) -> u64 {
91 self.timestamp
92 }
93
94 fn withdrawals(&self) -> Option<&Vec<Withdrawal>> {
95 self.withdrawals.as_ref()
96 }
97
98 fn parent_beacon_block_root(&self) -> Option<B256> {
99 self.parent_beacon_block_root
100 }
101}
102
103#[cfg(feature = "op")]
104impl PayloadAttributes for op_alloy_rpc_types_engine::OpPayloadAttributes {
105 fn timestamp(&self) -> u64 {
106 self.payload_attributes.timestamp
107 }
108
109 fn withdrawals(&self) -> Option<&Vec<Withdrawal>> {
110 self.payload_attributes.withdrawals.as_ref()
111 }
112
113 fn parent_beacon_block_root(&self) -> Option<B256> {
114 self.payload_attributes.parent_beacon_block_root
115 }
116}
117
118pub trait PayloadAttributesBuilder<Attributes>: Send + Sync + 'static {
120 fn build(&self, timestamp: u64) -> Attributes;
122}