@@ -328,47 +328,49 @@ def sign_transaction(self, json_tx: Any) -> None:
328
328
json_tx ["y_parity" ] = json_tx ["v" ]
329
329
330
330
331
- def convert_pydantic_tx_to_canonical (tx , fork ):
332
- """
333
- Convert a Pydantic Transaction to the canonical transaction class for the given fork.
334
- """
335
-
336
- def convert_access_list (access_list ):
337
- if not access_list :
338
- return []
339
- AccessCls = getattr (fork , "Access" , None )
340
- return [
341
- AccessCls (
342
- account = entry .address ,
343
- slots = tuple (entry .storage_keys ),
331
+ def _convert_access_list (access_list , fork ):
332
+ if not access_list :
333
+ return []
334
+ AccessCls = getattr (fork , "Access" , None )
335
+ return [
336
+ AccessCls (
337
+ account = entry .address ,
338
+ slots = tuple (entry .storage_keys ),
339
+ )
340
+ for entry in access_list
341
+ ]
342
+
343
+
344
+ def _convert_authorizations (auth_list , fork ):
345
+ if not auth_list :
346
+ return []
347
+ AuthorizationCls = getattr (fork , "Authorization" , None )
348
+ result = []
349
+ for entry in auth_list :
350
+ d = entry .model_dump ()
351
+ result .append (
352
+ AuthorizationCls (
353
+ chain_id = U256 (d .get ("chain_id" , 0 )),
354
+ address = d ["address" ],
355
+ nonce = U64 (d .get ("nonce" , 0 )),
356
+ y_parity = U8 (d .get ("v" , d .get ("y_parity" , 0 ))),
357
+ r = U256 (d ["r" ]),
358
+ s = U256 (d ["s" ]),
344
359
)
345
- for entry in access_list
346
- ]
360
+ )
361
+ return result
347
362
348
- def convert_authorizations (auth_list ):
349
- if not auth_list :
350
- return []
351
- AuthorizationCls = getattr (fork , "Authorization" , None )
352
- result = []
353
- for entry in auth_list :
354
- d = entry .model_dump ()
355
- result .append (
356
- AuthorizationCls (
357
- chain_id = U256 (d .get ("chain_id" , 0 )),
358
- address = d ["address" ],
359
- nonce = U64 (d .get ("nonce" , 0 )),
360
- y_parity = U8 (d .get ("v" , d .get ("y_parity" , 0 ))),
361
- r = U256 (d ["r" ]),
362
- s = U256 (d ["s" ]),
363
- )
364
- )
365
- return result
366
363
367
- def to_bytes20 (val ):
368
- if val is None :
369
- return Bytes0 ()
370
- return Bytes20 (val )
364
+ def _to_bytes20 (val ):
365
+ if val is None :
366
+ return Bytes0 ()
367
+ return Bytes20 (val )
371
368
369
+
370
+ def convert_pydantic_tx_to_canonical (tx , fork ):
371
+ """
372
+ Convert a Pydantic Transaction to the canonical transaction class for the given fork.
373
+ """
372
374
tx_type = tx .ty or 0
373
375
374
376
# SetCodeTransaction (Type 4)
@@ -379,11 +381,14 @@ def to_bytes20(val):
379
381
max_priority_fee_per_gas = Uint (tx .max_priority_fee_per_gas or 0 ),
380
382
max_fee_per_gas = Uint (tx .max_fee_per_gas or 0 ),
381
383
gas = Uint (tx .gas_limit ),
382
- to = to_bytes20 (tx .to ),
384
+ to = _to_bytes20 (tx .to ),
383
385
value = U256 (tx .value ),
384
386
data = tx .data ,
385
- access_list = convert_access_list (tx .access_list ),
386
- authorizations = convert_authorizations (tx .authorization_list or []),
387
+ access_list = _convert_access_list (tx .access_list , fork ),
388
+ authorizations = _convert_authorizations (
389
+ tx .authorization_list or [],
390
+ fork ,
391
+ ),
387
392
y_parity = U256 (tx .v ),
388
393
r = U256 (tx .r ),
389
394
s = U256 (tx .s ),
@@ -397,10 +402,10 @@ def to_bytes20(val):
397
402
max_priority_fee_per_gas = Uint (tx .max_priority_fee_per_gas or 0 ),
398
403
max_fee_per_gas = Uint (tx .max_fee_per_gas or 0 ),
399
404
gas = Uint (tx .gas_limit ),
400
- to = to_bytes20 (tx .to ),
405
+ to = _to_bytes20 (tx .to ),
401
406
value = U256 (tx .value ),
402
407
data = tx .data ,
403
- access_list = convert_access_list (tx .access_list ),
408
+ access_list = _convert_access_list (tx .access_list , fork ),
404
409
max_fee_per_blob_gas = Uint (tx .max_fee_per_blob_gas or 0 ),
405
410
blob_versioned_hashes = tx .blob_versioned_hashes or (),
406
411
y_parity = U256 (tx .v ),
@@ -416,10 +421,10 @@ def to_bytes20(val):
416
421
max_priority_fee_per_gas = Uint (tx .max_priority_fee_per_gas or 0 ),
417
422
max_fee_per_gas = Uint (tx .max_fee_per_gas or 0 ),
418
423
gas = Uint (tx .gas_limit ),
419
- to = to_bytes20 (tx .to ),
424
+ to = _to_bytes20 (tx .to ),
420
425
value = U256 (tx .value ),
421
426
data = tx .data ,
422
- access_list = convert_access_list (tx .access_list ),
427
+ access_list = _convert_access_list (tx .access_list , fork ),
423
428
y_parity = U256 (tx .v ),
424
429
r = U256 (tx .r ),
425
430
s = U256 (tx .s ),
@@ -432,10 +437,10 @@ def to_bytes20(val):
432
437
nonce = U256 (tx .nonce ),
433
438
gas_price = Uint (tx .gas_price or 0 ),
434
439
gas = Uint (tx .gas_limit ),
435
- to = to_bytes20 (tx .to ),
440
+ to = _to_bytes20 (tx .to ),
436
441
value = U256 (tx .value ),
437
442
data = tx .data ,
438
- access_list = convert_access_list (tx .access_list ),
443
+ access_list = _convert_access_list (tx .access_list , fork ),
439
444
y_parity = U256 (tx .v ),
440
445
r = U256 (tx .r ),
441
446
s = U256 (tx .s ),
@@ -451,7 +456,7 @@ def to_bytes20(val):
451
456
nonce = U256 (tx .nonce ),
452
457
gas_price = Uint (tx .gas_price or 0 ),
453
458
gas = Uint (tx .gas_limit ),
454
- to = to_bytes20 (tx .to ),
459
+ to = _to_bytes20 (tx .to ),
455
460
value = U256 (tx .value ),
456
461
data = tx .data ,
457
462
v = U256 (tx .v ),
0 commit comments