Skip to content

Commit 4223590

Browse files
committed
pyright fixes (genesis.py)
1 parent 33433c8 commit 4223590

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/ethereum/genesis.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import json
1616
import pkgutil
1717
from dataclasses import dataclass
18-
from typing import Any, Callable, Dict, Generic, Type, TypeVar
18+
from typing import Any, Callable, Dict, Generic, Type, TypeVar, Union
1919

2020
from ethereum_rlp import rlp
2121
from ethereum_types.bytes import Bytes, Bytes8, Bytes32, FixedBytes
@@ -83,7 +83,7 @@ class GenesisConfiguration:
8383
[`timestamp`]: ref:ethereum.frontier.blocks.Header.timestamp
8484
"""
8585

86-
initial_accounts: Dict[str, Dict]
86+
initial_accounts: Dict[str, Dict[str, Union[str, Dict[str, str]]]]
8787
"""
8888
State of the blockchain at genesis.
8989
"""
@@ -204,16 +204,31 @@ def add_genesis_block(
204204

205205
for hex_address, account in genesis.initial_accounts.items():
206206
address = hardfork.hex_to_address(hex_address)
207+
208+
nonce = account.get("nonce", "0")
209+
assert isinstance(nonce, (str, int))
210+
211+
balance = account.get("balance", "0")
212+
assert isinstance(balance, str)
213+
214+
code = account.get("code", "0x")
215+
assert isinstance(code, str)
216+
207217
hardfork.set_account(
208218
chain.state,
209219
address,
210220
hardfork.Account(
211-
Uint(int(account.get("nonce", "0"))),
212-
hex_or_base_10_str_to_u256(account.get("balance", 0)),
213-
hex_to_bytes(account.get("code", "0x")),
221+
Uint(int(nonce)),
222+
hex_or_base_10_str_to_u256(balance),
223+
hex_to_bytes(code),
214224
),
215225
)
216-
for key, value in account.get("storage", {}).items():
226+
227+
maybe_storage = account.get("storage", {})
228+
assert isinstance(maybe_storage, dict)
229+
storage: Dict[str, str] = maybe_storage
230+
231+
for key, value in storage.items():
217232
hardfork.set_storage(
218233
chain.state, address, hex_to_bytes32(key), hex_to_u256(value)
219234
)

0 commit comments

Comments
 (0)