resolve linting problems, except ssz-partials
This commit is contained in:
parent
df25f22f01
commit
7df788c7d5
|
@ -18,8 +18,8 @@ from eth2spec.utils.ssz.ssz_impl import (
|
|||
signing_root,
|
||||
)
|
||||
from eth2spec.utils.ssz.ssz_typing import (
|
||||
uint8, uint16, uint32, uint64, uint128, uint256,
|
||||
Container, Vector, BytesN
|
||||
# unused: uint8, uint16, uint32, uint128, uint256,
|
||||
uint64, Container, Vector, BytesN
|
||||
)
|
||||
from eth2spec.utils.hash_function import hash
|
||||
from eth2spec.utils.bls import (
|
||||
|
|
|
@ -68,7 +68,7 @@ def get_spec(file_name: str) -> List[str]:
|
|||
for type_line in ssz_type:
|
||||
if len(type_line) > 0:
|
||||
code_lines.append(' ' + type_line)
|
||||
code_lines.append('\n')
|
||||
code_lines.append('')
|
||||
for (ssz_type_name, _) in type_defs:
|
||||
code_lines.append(f' global_vars["{ssz_type_name}"] = {ssz_type_name}')
|
||||
code_lines.append(' global_vars["ssz_types"] = [')
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
|
||||
from eth2spec.utils.ssz.ssz_typing import *
|
||||
from eth2spec.utils.ssz.ssz_typing import (
|
||||
is_uint_type, is_bool_type, is_list_type,
|
||||
is_vector_type, is_bytes_type, is_bytesn_type, is_container_type,
|
||||
read_vector_elem_type, read_list_elem_type,
|
||||
Vector, BytesN
|
||||
)
|
||||
|
||||
|
||||
def decode(data, typ):
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
|
||||
from eth2spec.utils.ssz.ssz_typing import *
|
||||
from eth2spec.utils.ssz.ssz_typing import (
|
||||
is_uint_type, is_bool_type, is_list_type, is_vector_type, is_container_type,
|
||||
read_elem_type,
|
||||
uint
|
||||
)
|
||||
|
||||
|
||||
def encode(value, typ, include_hash_tree_roots=False):
|
||||
|
|
|
@ -2,9 +2,15 @@ from random import Random
|
|||
from typing import Any
|
||||
from enum import Enum
|
||||
|
||||
from eth2spec.utils.ssz.ssz_typing import *
|
||||
from eth2spec.utils.ssz.ssz_impl import is_basic_type
|
||||
|
||||
from eth2spec.utils.ssz.ssz_typing import (
|
||||
is_uint_type, is_bool_type, is_list_type,
|
||||
is_vector_type, is_bytes_type, is_bytesn_type, is_container_type,
|
||||
read_vector_elem_type, read_list_elem_type,
|
||||
uint_byte_size
|
||||
)
|
||||
|
||||
# in bytes
|
||||
UINT_SIZES = [1, 2, 4, 8, 16, 32]
|
||||
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
from .ssz_impl import *
|
||||
from .ssz_partials import *
|
|
@ -1,5 +1,11 @@
|
|||
from ..merkle_minimal import merkleize_chunks, hash
|
||||
from .ssz_typing import *
|
||||
from eth2spec.utils.ssz.ssz_typing import (
|
||||
is_uint_type, is_bool_type, is_container_type,
|
||||
is_list_kind, is_vector_kind,
|
||||
read_vector_elem_type, read_elem_type,
|
||||
uint_byte_size,
|
||||
infer_input_type
|
||||
)
|
||||
|
||||
# SSZ Serialization
|
||||
# -----------------------------
|
||||
|
@ -22,6 +28,7 @@ def serialize_basic(value, typ):
|
|||
else:
|
||||
raise Exception("Type not supported: {}".format(typ))
|
||||
|
||||
|
||||
def deserialize_basic(value, typ):
|
||||
if is_uint_type(typ):
|
||||
return typ(int.from_bytes(value, 'little'))
|
||||
|
@ -148,4 +155,3 @@ def signing_root(obj, typ):
|
|||
# ignore last field
|
||||
leaves = [hash_tree_root(field_value, typ=field_typ) for field_value, field_typ in obj.get_typed_values()[:-1]]
|
||||
return merkleize_chunks(chunkify(b''.join(leaves)))
|
||||
|
||||
|
|
|
@ -3,10 +3,6 @@ from typing import List, Iterable, TypeVar, Type, NewType
|
|||
from typing import Union
|
||||
from typing_inspect import get_origin
|
||||
|
||||
T = TypeVar('T')
|
||||
L = TypeVar('L')
|
||||
|
||||
|
||||
# SSZ integers
|
||||
# -----------------------------
|
||||
|
||||
|
@ -21,6 +17,7 @@ class uint(int):
|
|||
|
||||
class uint8(uint):
|
||||
byte_len = 1
|
||||
|
||||
def __new__(cls, value, *args, **kwargs):
|
||||
if value.bit_length() > 8:
|
||||
raise ValueError("value out of bounds for uint8")
|
||||
|
@ -32,6 +29,7 @@ byte = NewType('byte', uint8)
|
|||
|
||||
class uint16(uint):
|
||||
byte_len = 2
|
||||
|
||||
def __new__(cls, value, *args, **kwargs):
|
||||
if value.bit_length() > 16:
|
||||
raise ValueError("value out of bounds for uint16")
|
||||
|
@ -40,6 +38,7 @@ class uint16(uint):
|
|||
|
||||
class uint32(uint):
|
||||
byte_len = 4
|
||||
|
||||
def __new__(cls, value, *args, **kwargs):
|
||||
if value.bit_length() > 32:
|
||||
raise ValueError("value out of bounds for uint16")
|
||||
|
@ -52,6 +51,7 @@ uint64 = NewType('uint64', int)
|
|||
|
||||
class uint128(uint):
|
||||
byte_len = 16
|
||||
|
||||
def __new__(cls, value, *args, **kwargs):
|
||||
if value.bit_length() > 128:
|
||||
raise ValueError("value out of bounds for uint128")
|
||||
|
@ -60,6 +60,7 @@ class uint128(uint):
|
|||
|
||||
class uint256(uint):
|
||||
byte_len = 32
|
||||
|
||||
def __new__(cls, value, *args, **kwargs):
|
||||
if value.bit_length() > 256:
|
||||
raise ValueError("value out of bounds for uint256")
|
||||
|
@ -400,9 +401,11 @@ def get_zero_value(typ):
|
|||
return Exception("Type not supported: {}".format(typ))
|
||||
return result
|
||||
|
||||
|
||||
# Type helpers
|
||||
# -----------------------------
|
||||
|
||||
|
||||
def infer_type(obj):
|
||||
if is_uint_type(obj.__class__):
|
||||
return obj.__class__
|
||||
|
|
Loading…
Reference in New Issue