Skip to content

Commit 5a17bd9

Browse files
committed
review fixes
1 parent e1dc6a3 commit 5a17bd9

File tree

2 files changed

+65
-48
lines changed

2 files changed

+65
-48
lines changed

src/ethereum_spec_tools/evm_tools/t8n/env.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,15 @@ def read_randao(self, data: Any, t8n: "T8N") -> None:
372372
left_pad_zero_bytes(hex_to_bytes(current_random), 32)
373373
)
374374

375+
def _to_canonical_withdrawal(self, raw, fork):
376+
"""Convert raw withdrawal to canonical format."""
377+
return fork.Withdrawal(
378+
index=U64(raw.index),
379+
validator_index=U64(raw.validator_index),
380+
address=raw.address,
381+
amount=U256(raw.amount),
382+
)
383+
375384
def read_withdrawals_pydantic(self, data: Any, t8n: "T8N") -> None:
376385
"""
377386
Read the withdrawals from the data.
@@ -387,7 +396,10 @@ def to_canonical_withdrawal(raw):
387396
address=raw.address,
388397
amount=U256(raw.amount),
389398
)
390-
self.withdrawals = tuple(to_canonical_withdrawal(wd) for wd in raw_withdrawals)
399+
self.withdrawals = tuple(
400+
self._to_canonical_withdrawal(wd, t8n.fork)
401+
for wd in raw_withdrawals
402+
)
391403
else:
392404
self.withdrawals = ()
393405

src/ethereum_spec_tools/evm_tools/t8n/t8n_types.py

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -328,47 +328,49 @@ def sign_transaction(self, json_tx: Any) -> None:
328328
json_tx["y_parity"] = json_tx["v"]
329329

330330

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"]),
344359
)
345-
for entry in access_list
346-
]
360+
)
361+
return result
347362

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
366363

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)
371368

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+
"""
372374
tx_type = tx.ty or 0
373375

374376
# SetCodeTransaction (Type 4)
@@ -379,11 +381,14 @@ def to_bytes20(val):
379381
max_priority_fee_per_gas=Uint(tx.max_priority_fee_per_gas or 0),
380382
max_fee_per_gas=Uint(tx.max_fee_per_gas or 0),
381383
gas=Uint(tx.gas_limit),
382-
to=to_bytes20(tx.to),
384+
to=_to_bytes20(tx.to),
383385
value=U256(tx.value),
384386
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+
),
387392
y_parity=U256(tx.v),
388393
r=U256(tx.r),
389394
s=U256(tx.s),
@@ -397,10 +402,10 @@ def to_bytes20(val):
397402
max_priority_fee_per_gas=Uint(tx.max_priority_fee_per_gas or 0),
398403
max_fee_per_gas=Uint(tx.max_fee_per_gas or 0),
399404
gas=Uint(tx.gas_limit),
400-
to=to_bytes20(tx.to),
405+
to=_to_bytes20(tx.to),
401406
value=U256(tx.value),
402407
data=tx.data,
403-
access_list=convert_access_list(tx.access_list),
408+
access_list=_convert_access_list(tx.access_list, fork),
404409
max_fee_per_blob_gas=Uint(tx.max_fee_per_blob_gas or 0),
405410
blob_versioned_hashes=tx.blob_versioned_hashes or (),
406411
y_parity=U256(tx.v),
@@ -416,10 +421,10 @@ def to_bytes20(val):
416421
max_priority_fee_per_gas=Uint(tx.max_priority_fee_per_gas or 0),
417422
max_fee_per_gas=Uint(tx.max_fee_per_gas or 0),
418423
gas=Uint(tx.gas_limit),
419-
to=to_bytes20(tx.to),
424+
to=_to_bytes20(tx.to),
420425
value=U256(tx.value),
421426
data=tx.data,
422-
access_list=convert_access_list(tx.access_list),
427+
access_list=_convert_access_list(tx.access_list, fork),
423428
y_parity=U256(tx.v),
424429
r=U256(tx.r),
425430
s=U256(tx.s),
@@ -432,10 +437,10 @@ def to_bytes20(val):
432437
nonce=U256(tx.nonce),
433438
gas_price=Uint(tx.gas_price or 0),
434439
gas=Uint(tx.gas_limit),
435-
to=to_bytes20(tx.to),
440+
to=_to_bytes20(tx.to),
436441
value=U256(tx.value),
437442
data=tx.data,
438-
access_list=convert_access_list(tx.access_list),
443+
access_list=_convert_access_list(tx.access_list, fork),
439444
y_parity=U256(tx.v),
440445
r=U256(tx.r),
441446
s=U256(tx.s),
@@ -451,7 +456,7 @@ def to_bytes20(val):
451456
nonce=U256(tx.nonce),
452457
gas_price=Uint(tx.gas_price or 0),
453458
gas=Uint(tx.gas_limit),
454-
to=to_bytes20(tx.to),
459+
to=_to_bytes20(tx.to),
455460
value=U256(tx.value),
456461
data=tx.data,
457462
v=U256(tx.v),

0 commit comments

Comments
 (0)