From 9fc197af672fd2a237d80efa987f5e840341091f Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 10 Jun 2019 11:10:13 -0400 Subject: [PATCH] class Bytes32 --- scripts/build_spec.py | 7 ++++--- .../pyspec/eth2spec/utils/ssz/ssz_typing.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index 7a51970e3..087a88f98 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -25,7 +25,8 @@ from eth2spec.utils.ssz.ssz_impl import ( ) from eth2spec.utils.ssz.ssz_typing import ( # unused: uint8, uint16, uint32, uint128, uint256, - uint64, Container, Vector, BytesN + uint64, Container, Vector, + Bytes4, Bytes32, Bytes48, Bytes96, ) from eth2spec.utils.bls import ( bls_aggregate_pubkeys, @@ -52,7 +53,8 @@ from eth2spec.utils.ssz.ssz_impl import ( ) from eth2spec.utils.ssz.ssz_typing import ( # unused: uint8, uint16, uint32, uint128, uint256, - uint64, Container, Vector, BytesN + uint64, Container, Vector, + Bytes4, Bytes32, Bytes48, Bytes96, ) from eth2spec.utils.bls import ( bls_aggregate_pubkeys, @@ -132,7 +134,6 @@ def objects_to_spec(functions: Dict[str, str], """ new_type_definitions = \ '\n'.join(['''%s = NewType('%s', %s)''' % (key, key, value) for key, value in new_types.items()]) - new_type_definitions += '\n' + '\n'.join(['Bytes%s = BytesN[%s]' % (n, n) for n in byte_types]) functions_spec = '\n\n'.join(functions.values()) constants_spec = '\n'.join(map(lambda x: '%s = %s' % (x, constants[x]), constants)) ssz_objects_instantiation_spec = '\n\n'.join(ssz_objects.values()) diff --git a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py index 368041f90..e40c904ca 100644 --- a/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py +++ b/test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py @@ -390,6 +390,22 @@ class BytesN(bytes, metaclass=BytesNMeta): return hash_tree_root(self, self.__class__) +class Bytes4(BytesN): + length = 4 + + +class Bytes32(BytesN): + length = 32 + + +class Bytes48(BytesN): + length = 48 + + +class Bytes96(BytesN): + length = 96 + + # SSZ Defaults # ----------------------------- def get_zero_value(typ):