Skip to content

Commit 7292acd

Browse files
committed
rem unnecessary checks
1 parent 1f51eaf commit 7292acd

File tree

2 files changed

+18
-35
lines changed

2 files changed

+18
-35
lines changed

src/ethereum_spec_tools/evm_tools/t8n/env.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ def read_excess_blob_gas(self, data: Any, t8n: "T8N") -> None:
8888
if not t8n.fork.is_after_fork("ethereum.cancun"):
8989
return
9090

91-
if hasattr(data, "excess_blob_gas") and data.excess_blob_gas is not None:
91+
if data.excess_blob_gas is not None:
9292
self.excess_blob_gas = U64(data.excess_blob_gas)
9393

94-
if hasattr(data, "parent_excess_blob_gas") and data.parent_excess_blob_gas is not None:
94+
if data.parent_excess_blob_gas is not None:
9595
self.parent_excess_blob_gas = U64(data.parent_excess_blob_gas)
9696

97-
if hasattr(data, "parent_blob_gas_used") and data.parent_blob_gas_used is not None:
97+
if data.parent_blob_gas_used is not None:
9898
self.parent_blob_gas_used = U64(data.parent_blob_gas_used)
9999

100100
if self.excess_blob_gas is not None:
@@ -154,16 +154,16 @@ def read_base_fee_per_gas(self, data: Any, t8n: "T8N") -> None:
154154
self.base_fee_per_gas = None
155155

156156
if t8n.fork.is_after_fork("ethereum.london"):
157-
if hasattr(data, "base_fee_per_gas") and data.base_fee_per_gas is not None:
157+
if data.base_fee_per_gas is not None:
158158
self.base_fee_per_gas = Uint(data.base_fee_per_gas)
159159

160-
if hasattr(data, "parent_gas_used") and data.parent_gas_used is not None:
160+
if data.parent_gas_used is not None:
161161
self.parent_gas_used = Uint(data.parent_gas_used)
162162

163-
if hasattr(data, "parent_gas_limit") and data.parent_gas_limit is not None:
163+
if data.parent_gas_limit is not None:
164164
self.parent_gas_limit = Uint(data.parent_gas_limit)
165165

166-
if hasattr(data, "parent_base_fee_per_gas") and data.parent_base_fee_per_gas is not None:
166+
if data.parent_base_fee_per_gas is not None:
167167
self.parent_base_fee_per_gas = Uint(data.parent_base_fee_per_gas)
168168

169169
if self.base_fee_per_gas is None:
@@ -221,7 +221,7 @@ def read_block_difficulty(self, data: Any, t8n: "T8N") -> None:
221221
self.parent_ommers_hash = None
222222
if t8n.fork.is_after_fork("ethereum.paris"):
223223
return
224-
elif hasattr(data, "difficulty") and data.difficulty is not None:
224+
elif data.difficulty is not None:
225225
self.block_difficulty = Uint(data.difficulty)
226226
else:
227227
self.parent_timestamp = U256(data.parent_timestamp)
@@ -233,7 +233,7 @@ def read_block_difficulty(self, data: Any, t8n: "T8N") -> None:
233233
self.parent_difficulty,
234234
]
235235
if t8n.fork.is_after_fork("ethereum.byzantium"):
236-
if hasattr(data, "parent_ommers_hash") and data.parent_ommers_hash is not None:
236+
if data.parent_ommers_hash is not None:
237237
EMPTY_OMMER_HASH = keccak256(rlp.encode([]))
238238
self.parent_ommers_hash = Hash32(
239239
data.parent_ommers_hash
@@ -281,7 +281,7 @@ def read_ommers(self, data: Any, t8n: "T8N") -> None:
281281
needed to obtain the Header.
282282
"""
283283
ommers = []
284-
if hasattr(data, "ommers") and data.ommers is not None:
284+
if data.ommers is not None:
285285
for ommer in data.ommers:
286286
ommers.append(
287287
Ommer(

src/ethereum_spec_tools/evm_tools/t8n/t8n_types.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,16 @@ def __init__(self, t8n: "T8N", stdin: Optional[Dict] = None):
4242
)
4343

4444
if t8n.fork.proof_of_stake and canonical_account == EMPTY_ACCOUNT:
45-
addr_hex = addr_bytes.hex() if isinstance(addr_bytes, bytes) else str(addr_bytes)
46-
raise StateWithEmptyAccount(f"Empty account at {addr_hex}.")
47-
45+
raise StateWithEmptyAccount(
46+
f"Empty account at {addr_bytes.hex()}."
47+
)
4848
t8n.fork.set_account(state, addr_bytes, canonical_account)
4949

5050
if account.storage and account.storage.root:
5151
for storage_key, storage_value in account.storage.root.items():
52-
if isinstance(storage_key, int):
53-
storage_key_bytes = storage_key.to_bytes(32, byteorder='big')
54-
else:
55-
storage_key_bytes = storage_key
56-
52+
storage_key_bytes = storage_key.to_bytes(
53+
32, byteorder='big'
54+
)
5755
set_storage(
5856
state,
5957
addr_bytes,
@@ -260,17 +258,12 @@ def sign_transaction(self, json_tx: Any) -> None:
260258
def convert_pydantic_tx_to_canonical(tx, fork):
261259
"""
262260
Convert a Pydantic Transaction to the canonical transaction class for the given fork.
263-
fork: The fork object (e.g., self.fork from ForkLoad)
264261
"""
265-
if isinstance(tx, list):
266-
return [convert_pydantic_tx_to_canonical(t, fork) for t in tx]
267262

268263
def convert_access_list(access_list):
269264
if not access_list:
270265
return []
271266
AccessCls = getattr(fork, "Access", None)
272-
if AccessCls is None:
273-
from ethereum.arrow_glacier.transactions import Access as AccessCls
274267
return [
275268
AccessCls(
276269
account=entry.address,
@@ -283,11 +276,9 @@ def convert_authorizations(auth_list):
283276
if not auth_list:
284277
return []
285278
AuthorizationCls = getattr(fork, "Authorization", None)
286-
if AuthorizationCls is None:
287-
from ethereum.osaka.fork_types import Authorization as AuthorizationCls
288279
result = []
289280
for entry in auth_list:
290-
d = entry.dict() if hasattr(entry, "dict") else dict(entry)
281+
d = entry.model_dump()
291282
result.append(
292283
AuthorizationCls(
293284
chain_id=U256(d.get("chain_id", 0)),
@@ -318,15 +309,7 @@ def convert_authorizations(auth_list):
318309
def to_bytes20(val):
319310
if val is None:
320311
return Bytes0()
321-
if isinstance(val, Bytes20):
322-
return val
323-
if isinstance(val, (bytes, bytearray)) and len(val) == 20:
324-
return Bytes20(val)
325-
if isinstance(val, (bytes, bytearray)) and len(val) == 0:
326-
return Bytes20(b"\x00" * 20)
327-
if isinstance(val, (bytes, bytearray)):
328-
return Bytes20(val.rjust(20, b"\x00"))
329-
return Bytes20(bytes(val).rjust(20, b"\x00"))
312+
return Bytes20(val)
330313

331314
# build the canonical transaction
332315
if tx_cls.__name__ == "FeeMarketTransaction":

0 commit comments

Comments
 (0)