1
1
use alloy:: {
2
2
consensus:: { TxEip1559 , TxEip2930 , TxEip4844 , TxLegacy } ,
3
- eips:: eip2930:: { AccessList , AccessListItem } ,
4
3
rpc:: types:: TransactionRequest ,
5
4
} ;
6
- use revm:: context:: { TransactTo , TxEnv } ;
5
+ use revm:: context:: TxEnv ;
7
6
use revm_primitives:: { hardfork:: SpecId , TxKind } ;
8
7
9
8
use super :: spec_id:: get_spec_id;
@@ -14,102 +13,89 @@ pub trait TxEnvModifier {
14
13
15
14
impl TxEnvModifier for TxLegacy {
16
15
fn modify ( & self , block_number : u64 , tx_env : & mut TxEnv ) {
17
- tx_env. gas_limit = self . gas_limit ;
18
- tx_env. gas_price = self . gas_price ;
19
- tx_env. gas_priority_fee = None ;
20
- tx_env. kind = match self . to {
21
- TxKind :: Call ( to) => TransactTo :: Call ( to) ,
22
- TxKind :: Create => TransactTo :: Create ,
23
- } ;
24
- tx_env. value = self . value ;
25
- tx_env. data = self . input . clone ( ) ;
26
- tx_env. chain_id = if get_spec_id ( block_number) . is_enabled_in ( SpecId :: SPURIOUS_DRAGON ) {
27
- Some ( 1 )
28
- } else {
29
- None
16
+ * tx_env = TxEnv {
17
+ tx_type : 0 ,
18
+ caller : tx_env. caller ,
19
+ gas_limit : self . gas_limit ,
20
+ gas_price : self . gas_price ,
21
+ kind : self . to ,
22
+ value : self . value ,
23
+ data : self . input . clone ( ) ,
24
+ nonce : self . nonce ,
25
+ chain_id : if get_spec_id ( block_number) . is_enabled_in ( SpecId :: SPURIOUS_DRAGON ) {
26
+ Some ( 1 )
27
+ } else {
28
+ None
29
+ } ,
30
+ access_list : Default :: default ( ) ,
31
+ gas_priority_fee : None ,
32
+ blob_hashes : Default :: default ( ) ,
33
+ max_fee_per_blob_gas : Default :: default ( ) ,
34
+ authorization_list : Default :: default ( ) ,
30
35
} ;
31
- tx_env. nonce = self . nonce ;
32
- tx_env. access_list = AccessList :: default ( ) ;
33
- tx_env. blob_hashes . clear ( ) ;
34
- tx_env. max_fee_per_blob_gas = 0 ;
35
36
}
36
37
}
37
38
38
- impl TxEnvModifier for TxEip1559 {
39
+ impl TxEnvModifier for TxEip2930 {
39
40
fn modify ( & self , _block_number : u64 , tx_env : & mut TxEnv ) {
40
- tx_env. gas_limit = self . gas_limit ;
41
- tx_env. gas_price = self . max_fee_per_gas ;
42
- tx_env. gas_priority_fee = Some ( self . max_priority_fee_per_gas ) ;
43
- tx_env. kind = match self . to {
44
- TxKind :: Call ( to) => TransactTo :: Call ( to) ,
45
- TxKind :: Create => TransactTo :: Create ,
41
+ * tx_env = TxEnv {
42
+ tx_type : 1 ,
43
+ caller : tx_env. caller ,
44
+ gas_limit : self . gas_limit ,
45
+ gas_price : self . gas_price ,
46
+ kind : self . to ,
47
+ value : self . value ,
48
+ data : self . input . clone ( ) ,
49
+ nonce : self . nonce ,
50
+ chain_id : Some ( self . chain_id ) ,
51
+ access_list : self . access_list . clone ( ) ,
52
+ gas_priority_fee : None ,
53
+ blob_hashes : Default :: default ( ) ,
54
+ max_fee_per_blob_gas : Default :: default ( ) ,
55
+ authorization_list : Default :: default ( ) ,
46
56
} ;
47
- tx_env. value = self . value ;
48
- tx_env. data = self . input . clone ( ) ;
49
- tx_env. chain_id = Some ( self . chain_id ) ;
50
- tx_env. nonce = self . nonce ;
51
- tx_env. access_list = AccessList :: from (
52
- self . access_list
53
- . iter ( )
54
- . map ( |l| AccessListItem {
55
- address : l. address ,
56
- storage_keys : l. storage_keys . clone ( ) ,
57
- } )
58
- . collect :: < Vec < _ > > ( ) ,
59
- ) ;
60
- tx_env. blob_hashes . clear ( ) ;
61
- tx_env. max_fee_per_blob_gas = 0 ;
62
57
}
63
58
}
64
59
65
- impl TxEnvModifier for TxEip2930 {
60
+ impl TxEnvModifier for TxEip1559 {
66
61
fn modify ( & self , _block_number : u64 , tx_env : & mut TxEnv ) {
67
- tx_env. gas_limit = self . gas_limit ;
68
- tx_env. gas_price = self . gas_price ;
69
- tx_env. gas_priority_fee = None ;
70
- tx_env. kind = match self . to {
71
- TxKind :: Call ( to) => TransactTo :: Call ( to) ,
72
- TxKind :: Create => TransactTo :: Create ,
62
+ * tx_env = TxEnv {
63
+ tx_type : 2 ,
64
+ caller : tx_env. caller ,
65
+ gas_limit : self . gas_limit ,
66
+ gas_price : self . max_fee_per_gas ,
67
+ kind : self . to ,
68
+ value : self . value ,
69
+ data : self . input . clone ( ) ,
70
+ nonce : self . nonce ,
71
+ chain_id : Some ( self . chain_id ) ,
72
+ access_list : self . access_list . clone ( ) ,
73
+ gas_priority_fee : Some ( self . max_priority_fee_per_gas ) ,
74
+ blob_hashes : Default :: default ( ) ,
75
+ max_fee_per_blob_gas : Default :: default ( ) ,
76
+ authorization_list : Default :: default ( ) ,
73
77
} ;
74
- tx_env. value = self . value ;
75
- tx_env. data = self . input . clone ( ) ;
76
- tx_env. chain_id = Some ( self . chain_id ) ;
77
- tx_env. nonce = self . nonce ;
78
- tx_env. access_list = AccessList :: from (
79
- self . access_list
80
- . iter ( )
81
- . map ( |l| AccessListItem {
82
- address : l. address ,
83
- storage_keys : l. storage_keys . clone ( ) ,
84
- } )
85
- . collect :: < Vec < _ > > ( ) ,
86
- ) ;
87
- tx_env. blob_hashes . clear ( ) ;
88
- tx_env. max_fee_per_blob_gas = 0 ;
89
78
}
90
79
}
91
80
92
81
impl TxEnvModifier for TxEip4844 {
93
82
fn modify ( & self , _block_number : u64 , tx_env : & mut TxEnv ) {
94
- tx_env. gas_limit = self . gas_limit ;
95
- tx_env. gas_price = self . max_fee_per_gas ;
96
- tx_env. gas_priority_fee = Some ( self . max_priority_fee_per_gas ) ;
97
- tx_env. kind = TransactTo :: Call ( self . to ) ;
98
- tx_env. value = self . value ;
99
- tx_env. data = self . input . clone ( ) ;
100
- tx_env. chain_id = Some ( self . chain_id ) ;
101
- tx_env. nonce = self . nonce ;
102
- tx_env. access_list = AccessList :: from (
103
- self . access_list
104
- . iter ( )
105
- . map ( |l| AccessListItem {
106
- address : l. address ,
107
- storage_keys : l. storage_keys . clone ( ) ,
108
- } )
109
- . collect :: < Vec < _ > > ( ) ,
110
- ) ;
111
- tx_env. blob_hashes . clone_from ( & self . blob_versioned_hashes ) ;
112
- tx_env. max_fee_per_blob_gas = self . max_fee_per_blob_gas ;
83
+ * tx_env = TxEnv {
84
+ tx_type : 3 ,
85
+ caller : tx_env. caller ,
86
+ gas_limit : self . gas_limit ,
87
+ gas_price : self . max_fee_per_gas ,
88
+ kind : TxKind :: Call ( self . to ) ,
89
+ value : self . value ,
90
+ data : self . input . clone ( ) ,
91
+ nonce : self . nonce ,
92
+ chain_id : Some ( self . chain_id ) ,
93
+ access_list : self . access_list . clone ( ) ,
94
+ gas_priority_fee : Some ( self . max_priority_fee_per_gas ) ,
95
+ blob_hashes : self . blob_versioned_hashes . clone ( ) ,
96
+ max_fee_per_blob_gas : self . max_fee_per_blob_gas ,
97
+ authorization_list : Default :: default ( ) ,
98
+ } ;
113
99
}
114
100
}
115
101
@@ -140,8 +126,8 @@ impl TxEnvModifier for TransactionRequest {
140
126
if let Some ( data) = self . input . input ( ) {
141
127
tx_env. data . clone_from ( data) ;
142
128
}
143
- if let Some ( nounce ) = self . nonce {
144
- tx_env. nonce = nounce ;
129
+ if let Some ( nonce ) = self . nonce {
130
+ tx_env. nonce = nonce ;
145
131
}
146
132
tx_env. chain_id = self . chain_id ;
147
133
if let Some ( access_list) = & self . access_list {
@@ -156,6 +142,7 @@ impl TxEnvModifier for TransactionRequest {
156
142
#[ cfg( test) ]
157
143
mod tests {
158
144
use alloy:: primitives:: bytes:: Bytes ;
145
+ use revm:: context:: TransactTo ;
159
146
use revm_primitives:: { TxKind , U256 } ;
160
147
161
148
use super :: * ;
@@ -204,7 +191,7 @@ mod tests {
204
191
assert_eq ! ( tx_env. value, U256 :: from( 1 ) ) ;
205
192
assert_eq ! ( tx_env. data. 0 , vec![ 1 , 2 , 3 ] ) ;
206
193
assert_eq ! ( tx_env. chain_id, Some ( 1 ) ) ;
207
- assert_eq ! ( tx_env. access_list, AccessList :: default ( ) ) ;
194
+ assert_eq ! ( tx_env. access_list, Default :: default ( ) ) ;
208
195
}
209
196
210
197
#[ test]
@@ -228,7 +215,7 @@ mod tests {
228
215
assert_eq ! ( tx_env. value, U256 :: from( 1 ) ) ;
229
216
assert_eq ! ( tx_env. data. 0 , vec![ 1 , 2 , 3 ] ) ;
230
217
assert_eq ! ( tx_env. chain_id, Some ( 1 ) ) ;
231
- assert_eq ! ( tx_env. access_list, AccessList :: default ( ) ) ;
218
+ assert_eq ! ( tx_env. access_list, Default :: default ( ) ) ;
232
219
}
233
220
234
221
#[ test]
@@ -256,7 +243,7 @@ mod tests {
256
243
assert_eq ! ( tx_env. value, U256 :: from( 1 ) ) ;
257
244
assert_eq ! ( tx_env. data. 0 , vec![ 1 , 2 , 3 ] ) ;
258
245
assert_eq ! ( tx_env. chain_id, Some ( 1 ) ) ;
259
- assert_eq ! ( tx_env. access_list, AccessList :: default ( ) ) ;
246
+ assert_eq ! ( tx_env. access_list, Default :: default ( ) ) ;
260
247
assert_eq ! ( tx_env. blob_hashes. len( ) , 0 ) ;
261
248
assert_eq ! ( tx_env. max_fee_per_blob_gas, 1 ) ;
262
249
}
0 commit comments