-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathattributes.rs
More file actions
110 lines (93 loc) · 3.29 KB
/
Copy pathattributes.rs
File metadata and controls
110 lines (93 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use alloy_eips::{eip4895::Withdrawals, Decodable2718};
use alloy_primitives::{Address, Bytes, B256};
use alloy_rpc_types::{
engine::{PayloadAttributes as EthPayloadAttributes, PayloadId},
Withdrawal,
};
use reth_ethereum::{
node::api::payload::{PayloadAttributes, PayloadBuilderAttributes},
TransactionSigned,
};
use reth_payload_builder::EthPayloadBuilderAttributes;
use serde::{Deserialize, Serialize};
use crate::error::EvolveEngineError;
/// Evolve payload attributes that support passing transactions via Engine API.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct EvolveEnginePayloadAttributes {
/// Standard Ethereum payload attributes.
#[serde(flatten)]
pub inner: EthPayloadAttributes,
/// Transactions to be included in the payload (passed via Engine API).
pub transactions: Option<Vec<Bytes>>,
/// Optional gas limit for the payload.
#[serde(rename = "gasLimit")]
pub gas_limit: Option<u64>,
}
impl PayloadAttributes for EvolveEnginePayloadAttributes {
fn timestamp(&self) -> u64 {
self.inner.timestamp()
}
fn withdrawals(&self) -> Option<&Vec<Withdrawal>> {
self.inner.withdrawals()
}
fn parent_beacon_block_root(&self) -> Option<B256> {
self.inner.parent_beacon_block_root()
}
}
/// Evolve payload builder attributes.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct EvolveEnginePayloadBuilderAttributes {
/// Ethereum payload builder attributes.
pub ethereum_attributes: EthPayloadBuilderAttributes,
/// Decoded transactions from the Engine API.
pub transactions: Vec<TransactionSigned>,
/// Gas limit for the payload.
pub gas_limit: Option<u64>,
}
impl PayloadBuilderAttributes for EvolveEnginePayloadBuilderAttributes {
type RpcPayloadAttributes = EvolveEnginePayloadAttributes;
type Error = EvolveEngineError;
fn try_new(
parent: B256,
attributes: EvolveEnginePayloadAttributes,
_version: u8,
) -> Result<Self, Self::Error> {
let ethereum_attributes = EthPayloadBuilderAttributes::new(parent, attributes.inner);
// Decode transactions from bytes if provided.
let transactions = attributes
.transactions
.unwrap_or_default()
.into_iter()
.map(|tx_bytes| {
TransactionSigned::network_decode(&mut tx_bytes.as_ref())
.map_err(|e| EvolveEngineError::InvalidTransactionData(e.to_string()))
})
.collect::<Result<Vec<_>, _>>()?;
Ok(Self {
ethereum_attributes,
transactions,
gas_limit: attributes.gas_limit,
})
}
fn payload_id(&self) -> PayloadId {
self.ethereum_attributes.id
}
fn parent(&self) -> B256 {
self.ethereum_attributes.parent
}
fn timestamp(&self) -> u64 {
self.ethereum_attributes.timestamp
}
fn parent_beacon_block_root(&self) -> Option<B256> {
self.ethereum_attributes.parent_beacon_block_root
}
fn suggested_fee_recipient(&self) -> Address {
self.ethereum_attributes.suggested_fee_recipient
}
fn prev_randao(&self) -> B256 {
self.ethereum_attributes.prev_randao
}
fn withdrawals(&self) -> &Withdrawals {
&self.ethereum_attributes.withdrawals
}
}