4
4
from dataclasses import dataclass
5
5
from typing import TYPE_CHECKING , Any , Dict , List , Optional , Tuple
6
6
7
- from ethereum_rlp import Simple , rlp
7
+ from ethereum_rlp import rlp
8
8
from ethereum_types .bytes import Bytes , Bytes20 , Bytes0
9
9
from ethereum .exceptions import StateWithEmptyAccount
10
10
from ethereum_types .numeric import U8 , U64 , U256 , Uint
@@ -110,13 +110,16 @@ def __init__(self, t8n: "T8N", stdin: List[Transaction] = None):
110
110
self .all_txs = []
111
111
112
112
if stdin is None :
113
- self .data : Simple = []
113
+ self .data : List [ Transaction ] = []
114
114
else :
115
115
self .data = stdin
116
116
117
117
for idx , raw_tx in enumerate (self .data ):
118
118
try :
119
- fork_tx = self .pydantic_to_fork_transaction (raw_tx )
119
+ fork_tx = convert_pydantic_tx_to_canonical (
120
+ raw_tx ,
121
+ self .t8n .fork ,
122
+ )
120
123
self .transactions .append (fork_tx )
121
124
self .successfully_parsed .append (idx )
122
125
self .all_txs .append (fork_tx )
@@ -191,9 +194,6 @@ def parse_json_tx(self, raw_tx: Any) -> Any:
191
194
192
195
return transaction
193
196
194
- def pydantic_to_fork_transaction (self , tx_model ):
195
- return convert_pydantic_tx_to_canonical (tx_model , self .t8n .fork )
196
-
197
197
def sign_transaction (self , json_tx : Any ) -> None :
198
198
"""
199
199
Sign a transaction. This function will be invoked if a `secretKey`
@@ -291,29 +291,16 @@ def convert_authorizations(auth_list):
291
291
)
292
292
return result
293
293
294
- # determine tx type
295
- tx_type = getattr (tx , "ty" , 0 )
296
- if hasattr (fork , "SetCodeTransaction" ) and tx_type == 4 :
297
- tx_cls = fork .SetCodeTransaction
298
- elif hasattr (fork , "BlobTransaction" ) and tx_type == 3 :
299
- tx_cls = fork .BlobTransaction
300
- elif hasattr (fork , "FeeMarketTransaction" ) and tx_type == 2 :
301
- tx_cls = fork .FeeMarketTransaction
302
- elif hasattr (fork , "AccessListTransaction" ) and tx_type == 1 :
303
- tx_cls = fork .AccessListTransaction
304
- else :
305
- tx_cls = getattr (fork , "LegacyTransaction" , None )
306
- if tx_cls is None :
307
- tx_cls = getattr (fork , "Transaction" )
308
-
309
294
def to_bytes20 (val ):
310
295
if val is None :
311
296
return Bytes0 ()
312
297
return Bytes20 (val )
313
298
314
- # build the canonical transaction
315
- if tx_cls .__name__ == "FeeMarketTransaction" :
316
- return tx_cls (
299
+ tx_type = tx .ty or 0
300
+
301
+ # SetCodeTransaction (Type 4)
302
+ if hasattr (fork , "SetCodeTransaction" ) and tx_type == 4 :
303
+ return fork .SetCodeTransaction (
317
304
chain_id = U64 (tx .chain_id ),
318
305
nonce = U256 (tx .nonce ),
319
306
max_priority_fee_per_gas = Uint (tx .max_priority_fee_per_gas or 0 ),
@@ -323,26 +310,34 @@ def to_bytes20(val):
323
310
value = U256 (tx .value ),
324
311
data = tx .data ,
325
312
access_list = convert_access_list (tx .access_list ),
313
+ authorizations = convert_authorizations (tx .authorization_list or []),
326
314
y_parity = U256 (tx .v ),
327
315
r = U256 (tx .r ),
328
316
s = U256 (tx .s ),
329
317
)
330
- elif tx_cls .__name__ == "AccessListTransaction" :
331
- return tx_cls (
318
+
319
+ # BlobTransaction (Type 3)
320
+ elif hasattr (fork , "BlobTransaction" ) and tx_type == 3 :
321
+ return fork .BlobTransaction (
332
322
chain_id = U64 (tx .chain_id ),
333
323
nonce = U256 (tx .nonce ),
334
- gas_price = Uint (tx .gas_price or 0 ),
324
+ max_priority_fee_per_gas = Uint (tx .max_priority_fee_per_gas or 0 ),
325
+ max_fee_per_gas = Uint (tx .max_fee_per_gas or 0 ),
335
326
gas = Uint (tx .gas_limit ),
336
327
to = to_bytes20 (tx .to ),
337
328
value = U256 (tx .value ),
338
329
data = tx .data ,
339
330
access_list = convert_access_list (tx .access_list ),
331
+ max_fee_per_blob_gas = Uint (tx .max_fee_per_blob_gas or 0 ),
332
+ blob_versioned_hashes = tx .blob_versioned_hashes or (),
340
333
y_parity = U256 (tx .v ),
341
334
r = U256 (tx .r ),
342
335
s = U256 (tx .s ),
343
336
)
344
- elif tx_cls .__name__ == "BlobTransaction" :
345
- return tx_cls (
337
+
338
+ # FeeMarketTransaction (Type 2)
339
+ elif hasattr (fork , "FeeMarketTransaction" ) and tx_type == 2 :
340
+ return fork .FeeMarketTransaction (
346
341
chain_id = U64 (tx .chain_id ),
347
342
nonce = U256 (tx .nonce ),
348
343
max_priority_fee_per_gas = Uint (tx .max_priority_fee_per_gas or 0 ),
@@ -352,29 +347,33 @@ def to_bytes20(val):
352
347
value = U256 (tx .value ),
353
348
data = tx .data ,
354
349
access_list = convert_access_list (tx .access_list ),
355
- max_fee_per_blob_gas = Uint (getattr (tx , "max_fee_per_blob_gas" , 0 )),
356
- blob_versioned_hashes = getattr (tx , "blob_versioned_hashes" , ()),
357
350
y_parity = U256 (tx .v ),
358
351
r = U256 (tx .r ),
359
352
s = U256 (tx .s ),
360
353
)
361
- elif tx_cls .__name__ == "SetCodeTransaction" :
362
- return tx_cls (
354
+
355
+ # AccessListTransaction (Type 1)
356
+ elif hasattr (fork , "AccessListTransaction" ) and tx_type == 1 :
357
+ return fork .AccessListTransaction (
363
358
chain_id = U64 (tx .chain_id ),
364
359
nonce = U256 (tx .nonce ),
365
- max_priority_fee_per_gas = Uint (tx .max_priority_fee_per_gas or 0 ),
366
- max_fee_per_gas = Uint (tx .max_fee_per_gas or 0 ),
360
+ gas_price = Uint (tx .gas_price or 0 ),
367
361
gas = Uint (tx .gas_limit ),
368
362
to = to_bytes20 (tx .to ),
369
363
value = U256 (tx .value ),
370
364
data = tx .data ,
371
365
access_list = convert_access_list (tx .access_list ),
372
- authorizations = convert_authorizations (getattr (tx , "authorization_list" , ())),
373
366
y_parity = U256 (tx .v ),
374
367
r = U256 (tx .r ),
375
368
s = U256 (tx .s ),
376
369
)
370
+
371
+ # Legacy Transaction (Type 0)
377
372
else :
373
+ tx_cls = getattr (fork , "LegacyTransaction" , None )
374
+ if tx_cls is None :
375
+ tx_cls = getattr (fork , "Transaction" )
376
+
378
377
return tx_cls (
379
378
nonce = U256 (tx .nonce ),
380
379
gas_price = Uint (tx .gas_price or 0 ),
0 commit comments