get rid of TypingList, add MutableSequence

This commit is contained in:
protolambda 2019-06-25 02:56:49 +02:00
parent 45dbf5a107
commit 054a157953
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
3 changed files with 6 additions and 5 deletions

View File

@ -37,8 +37,7 @@ from eth2spec.utils.bls import (
from eth2spec.utils.hash_function import hash
'''
PHASE1_IMPORTS = '''from typing import (
Any, Callable, Dict, Optional, Set, Sequence, Tuple,
List as TypingList
Any, Callable, Dict, Optional, Set, Sequence, MutableSequence, Tuple,
)
from dataclasses import (

View File

@ -318,7 +318,7 @@ def get_validators_custody_reveal_period(state: BeaconState,
### `replace_empty_or_append`
```python
def replace_empty_or_append(list: TypingList[Any], new_element: Any) -> int:
def replace_empty_or_append(list: MutableSequence[Any], new_element: Any) -> int:
for i in range(len(list)):
if is_empty(list[i]):
list[i] = new_element

View File

@ -252,9 +252,9 @@ def compute_crosslink_data_root(blocks: Sequence[ShardBlock]) -> Bytes32:
def is_power_of_two(value: int) -> bool:
return (value > 0) and (value & (value - 1) == 0)
def pad_to_power_of_2(values: TypingList[bytes]) -> TypingList[bytes]:
def pad_to_power_of_2(values: MutableSequence[bytes]) -> Sequence[bytes]:
while not is_power_of_two(len(values)):
values += [b'\x00' * BYTES_PER_SHARD_BLOCK_BODY]
values.append(b'\x00' * BYTES_PER_SHARD_BLOCK_BODY)
return values
def hash_tree_root_of_bytes(data: bytes) -> bytes:
@ -264,6 +264,8 @@ def compute_crosslink_data_root(blocks: Sequence[ShardBlock]) -> Bytes32:
return data + b'\x00' * (length - len(data))
return hash(
# TODO untested code.
# Need to either pass a typed list to hash-tree-root, or merkleize_chunks(values, pad_to=2**x)
hash_tree_root(pad_to_power_of_2([
hash_tree_root_of_bytes(
zpad(serialize(get_shard_header(block)), BYTES_PER_SHARD_BLOCK_BODY)