Skip to content

Commit 47490b5

Browse files
committed
Refactor some eth.typing types
1 parent 430fde7 commit 47490b5

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

eth/tools/builder/chain/builders.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
from eth.typing import (
5555
AccountState,
5656
GeneralState,
57+
VMFork,
58+
VMConfiguration,
5759
)
5860
from eth.validation import (
5961
validate_vm_configuration,
@@ -71,9 +73,6 @@
7173
)
7274

7375

74-
VMConfiguration = Iterable[Tuple[int, Type[BaseVM]]]
75-
76-
7776
def build(obj: Any, *applicators: Callable[..., Any]) -> Any:
7877
"""
7978
Run the provided object through the series of applicator functions.
@@ -159,7 +158,7 @@ def _is_homestead(vm_class: Type[BaseVM]) -> bool:
159158

160159

161160
@to_tuple
162-
def _set_vm_dao_support_false(vm_configuration: VMConfiguration) -> VMConfiguration:
161+
def _set_vm_dao_support_false(vm_configuration: VMConfiguration) -> Iterable[VMFork]:
163162
for fork_block, vm_class in vm_configuration:
164163
if _is_homestead(vm_class):
165164
yield fork_block, vm_class.configure(support_dao_fork=False)
@@ -187,7 +186,7 @@ def disable_dao_fork(chain_class: Type[BaseChain]) -> Type[BaseChain]:
187186

188187
@to_tuple
189188
def _set_vm_dao_fork_block_number(dao_fork_block_number: BlockNumber,
190-
vm_configuration: VMConfiguration) -> VMConfiguration:
189+
vm_configuration: VMConfiguration) -> Iterable[VMFork]:
191190
for fork_block, vm_class in vm_configuration:
192191
if _is_homestead(vm_class):
193192
yield fork_block, vm_class.configure(
@@ -257,7 +256,7 @@ def _get_default_genesis_params(genesis_state: AccountState) -> Iterable[Tuple[s
257256

258257

259258
@to_tuple
260-
def _mix_in_pow_mining(vm_configuration: VMConfiguration) -> VMConfiguration:
259+
def _mix_in_pow_mining(vm_configuration: VMConfiguration) -> Iterable[VMFork]:
261260
for fork_block, vm_class in vm_configuration:
262261
vm_class_with_pow_mining = type(vm_class.__name__, (POWMiningMixin, vm_class), {})
263262
yield fork_block, vm_class_with_pow_mining
@@ -289,7 +288,7 @@ def validate_seal(cls, header: BlockHeader) -> None:
289288

290289

291290
@to_tuple
292-
def _mix_in_disable_seal_validation(vm_configuration: VMConfiguration) -> VMConfiguration:
291+
def _mix_in_disable_seal_validation(vm_configuration: VMConfiguration) -> Iterable[VMFork]:
293292
for fork_block, vm_class in vm_configuration:
294293
vm_class_without_seal_validation = type(
295294
vm_class.__name__,

eth/typing.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
Iterable,
77
List,
88
NewType,
9+
Sequence,
910
Tuple,
10-
Union,
11+
Type,
1112
TypeVar,
1213
TYPE_CHECKING,
14+
Union,
1315
)
1416

1517
from eth_typing import (
1618
Address,
19+
BlockNumber,
20+
Hash32,
1721
HexStr,
1822
)
1923
from mypy_extensions import (
@@ -27,6 +31,9 @@
2731
from eth.utils.spoof import ( # noqa: F401
2832
SpoofTransaction
2933
)
34+
from eth.vm.base import ( # noqa: F401
35+
BaseVM
36+
)
3037

3138

3239
# TODO: Move into eth_typing
@@ -48,6 +55,17 @@
4855
List[Tuple[Address, Dict[str, Union[int, bytes, Dict[int, int]]]]]
4956
]
5057

58+
GenesisDict = Dict[str, Union[int, BlockNumber, bytes, Hash32]]
59+
60+
Normalizer = Callable[[Dict[Any, Any]], Dict[str, Any]]
61+
62+
RawAccountDetails = TypedDict('RawAccountDetails',
63+
{'balance': HexStr,
64+
'nonce': HexStr,
65+
'code': HexStr,
66+
'storage': Dict[HexStr, HexStr]
67+
})
68+
5169
TransactionDict = TypedDict('TransactionDict',
5270
{'nonce': int,
5371
'gasLimit': int,
@@ -58,10 +76,12 @@
5876
'secretKey': bytes,
5977
})
6078

61-
Normalizer = Callable[[Dict[Any, Any]], Dict[str, Any]]
62-
6379
TransactionNormalizer = Callable[[TransactionDict], TransactionDict]
6480

81+
VMFork = Tuple[BlockNumber, Type['BaseVM']]
82+
83+
VMConfiguration = Sequence[VMFork]
84+
6585
VRS = NewType("VRS", Tuple[int, int, int])
6686

6787
IntConvertible = Union[int, bytes, HexStr, str]

0 commit comments

Comments
 (0)