mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-19 23:19:28 +00:00
get rid of TypingList, add MutableSequence
This commit is contained in:
parent
45dbf5a107
commit
054a157953
@ -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 (
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user