1pub use alloy_eip2930::AccessList;
2pub use alloy_eip7702::SignedAuthorization;
3use context_interface::Transaction;
4use core::fmt::Debug;
5use primitives::{Address, Bytes, TxKind, B256, U256};
6use std::vec::Vec;
7
8#[derive(Clone, Debug, PartialEq, Eq)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct TxEnv {
12 pub tx_type: u8,
13 pub caller: Address,
15 pub gas_limit: u64,
17 pub gas_price: u128,
19 pub kind: TxKind,
21 pub value: U256,
23 pub data: Bytes,
25
26 pub nonce: u64,
28
29 pub chain_id: Option<u64>,
37
38 pub access_list: AccessList,
44
45 pub gas_priority_fee: Option<u128>,
51
52 pub blob_hashes: Vec<B256>,
60
61 pub max_fee_per_blob_gas: u128,
67
68 pub authorization_list: Vec<SignedAuthorization>,
77}
78
79impl Default for TxEnv {
80 fn default() -> Self {
81 Self {
82 tx_type: 0,
83 caller: Address::default(),
84 gas_limit: 30_000_000,
85 gas_price: 0,
86 kind: TxKind::Call(Address::default()),
87 value: U256::ZERO,
88 data: Bytes::default(),
89 nonce: 0,
90 chain_id: Some(1), access_list: Default::default(),
92 gas_priority_fee: Some(0),
93 blob_hashes: Vec::new(),
94 max_fee_per_blob_gas: 0,
95 authorization_list: Vec::new(),
96 }
97 }
98}
99
100impl Transaction for TxEnv {
101 type AccessList = AccessList;
102 type Authorization = SignedAuthorization;
103
104 fn tx_type(&self) -> u8 {
105 self.tx_type
106 }
107
108 fn kind(&self) -> TxKind {
109 self.kind
110 }
111
112 fn caller(&self) -> Address {
113 self.caller
114 }
115
116 fn gas_limit(&self) -> u64 {
117 self.gas_limit
118 }
119
120 fn gas_price(&self) -> u128 {
121 self.gas_price
122 }
123
124 fn value(&self) -> U256 {
125 self.value
126 }
127
128 fn nonce(&self) -> u64 {
129 self.nonce
130 }
131
132 fn chain_id(&self) -> Option<u64> {
133 self.chain_id
134 }
135
136 fn access_list(&self) -> Option<&Self::AccessList> {
137 Some(&self.access_list)
138 }
139
140 fn max_fee_per_gas(&self) -> u128 {
141 self.gas_price
142 }
143
144 fn max_fee_per_blob_gas(&self) -> u128 {
145 self.max_fee_per_blob_gas
146 }
147
148 fn authorization_list_len(&self) -> usize {
149 self.authorization_list.len()
150 }
151
152 fn authorization_list(&self) -> impl Iterator<Item = &Self::Authorization> {
153 self.authorization_list.iter()
154 }
155
156 fn input(&self) -> &Bytes {
157 &self.data
158 }
159
160 fn blob_versioned_hashes(&self) -> &[B256] {
161 &self.blob_hashes
162 }
163
164 fn max_priority_fee_per_gas(&self) -> Option<u128> {
165 self.gas_priority_fee
166 }
167}