Simplify minimal SSZ again
This commit is contained in:
parent
9f2d410a17
commit
306a613c8a
|
@ -55,7 +55,6 @@ def merger(oldfile:str, newfile:str) -> str:
|
|||
found_old = False
|
||||
for old_item in old_object_tuples:
|
||||
if old_item[0] == re.match(object_regex, new_item).group(0):
|
||||
print(old_item[0])
|
||||
old_item[1] = new_item
|
||||
found_old = True
|
||||
break
|
||||
|
@ -67,7 +66,6 @@ def merger(oldfile:str, newfile:str) -> str:
|
|||
def build_phase0_spec(sourcefile, outfile=None):
|
||||
code_lines = []
|
||||
code_lines.append("""
|
||||
|
||||
from typing import (
|
||||
Any,
|
||||
Dict,
|
||||
|
@ -75,16 +73,19 @@ from typing import (
|
|||
NewType,
|
||||
Tuple,
|
||||
)
|
||||
|
||||
from eth2spec.utils.minimal_ssz import (
|
||||
SSZType,
|
||||
hash_tree_root,
|
||||
signing_root,
|
||||
)
|
||||
|
||||
from eth2spec.utils.bls_stub import (
|
||||
bls_aggregate_pubkeys,
|
||||
bls_verify,
|
||||
bls_verify_multiple,
|
||||
)
|
||||
|
||||
from eth2spec.utils.hash_function import hash
|
||||
|
||||
|
||||
|
@ -146,6 +147,7 @@ def apply_constants_preset(preset: Dict[str, Any]):
|
|||
|
||||
# Initialize SSZ types again, to account for changed lengths
|
||||
init_SSZ_types()
|
||||
|
||||
""")
|
||||
|
||||
if outfile is not None:
|
||||
|
|
|
@ -9,12 +9,8 @@ ZERO_CHUNK = b'\x00' * BYTES_PER_CHUNK
|
|||
cached_typedefs = {}
|
||||
|
||||
|
||||
def SSZType(name, fields):
|
||||
def SSZType(fields):
|
||||
class SSZObject():
|
||||
if name is not None:
|
||||
__name__ = name
|
||||
__qualname__ = name
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
for f, t in fields.items():
|
||||
if f not in kwargs:
|
||||
|
@ -31,12 +27,9 @@ def SSZType(name, fields):
|
|||
def __str__(self):
|
||||
output = []
|
||||
for field in self.fields:
|
||||
output.append(f'{field}: {repr(getattr(self, field))},')
|
||||
output.append(f'{field}: {getattr(self, field)}')
|
||||
return "\n".join(output)
|
||||
|
||||
def __repr__(self):
|
||||
return name + "(**{\n " + str(self).replace("\n", "\n ") + "\n})"
|
||||
|
||||
def serialize(self):
|
||||
return serialize_value(self, self.__class__)
|
||||
|
||||
|
@ -44,19 +37,9 @@ def SSZType(name, fields):
|
|||
return hash_tree_root(self, self.__class__)
|
||||
|
||||
SSZObject.fields = fields
|
||||
|
||||
if name is not None:
|
||||
cached_typedefs[name] = SSZObject
|
||||
|
||||
return SSZObject
|
||||
|
||||
|
||||
def SSZTypeExtension(original_type, new_fields):
|
||||
typedef = cached_typedefs[original_type]
|
||||
typedef.fields.update(new_fields)
|
||||
return typedef
|
||||
|
||||
|
||||
class Vector():
|
||||
def __init__(self, items):
|
||||
self.items = items
|
||||
|
@ -334,7 +317,7 @@ def truncate(container):
|
|||
key: container.fields[key]
|
||||
for key in field_keys[:-1]
|
||||
}
|
||||
truncated_class = SSZType(None, truncated_fields)
|
||||
truncated_class = SSZType(truncated_fields)
|
||||
kwargs = {
|
||||
field: getattr(container, field)
|
||||
for field in field_keys[:-1]
|
||||
|
|
Loading…
Reference in New Issue