From 1d9a58f1e8d8e89f7f9d018b3989202a75aca4fc Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Tue, 2 Jun 2020 22:10:45 +0200 Subject: [PATCH] a few more cleanups --- beacon_chain/spec/datatypes.nim | 2 +- beacon_chain/ssz/types.nim | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/beacon_chain/spec/datatypes.nim b/beacon_chain/spec/datatypes.nim index 0e43d8ee0..a8483aeff 100644 --- a/beacon_chain/spec/datatypes.nim +++ b/beacon_chain/spec/datatypes.nim @@ -513,7 +513,7 @@ Json.useCustomSerialization(BitSeq): writer.writeValue "0x" & seq[byte](value).toHex template readValue*(reader: var JsonReader, value: var List) = - value = T readValue(reader, seq[type value[0]]) + value = type(value)(readValue(reader, seq[type value[0]])) template writeValue*(writer: var JsonWriter, value: List) = writeValue(writer, asSeq value) diff --git a/beacon_chain/ssz/types.nim b/beacon_chain/ssz/types.nim index b1481f70a..57d434113 100644 --- a/beacon_chain/ssz/types.nim +++ b/beacon_chain/ssz/types.nim @@ -10,6 +10,11 @@ const offsetSize* = 4 bytesPerChunk* = 32 +type + UintN* = SomeUnsignedInt # TODO: Add StUint here + BasicType* = bool|UintN + + Limit* = int64 # A few index types from here onwards: # * dataIdx - leaf index starting from 0 to maximum length of collection @@ -17,9 +22,9 @@ const # * vIdx - virtual index in merkle tree - the root is found at index 1, its # two children at 2, 3 then 4, 5, 6, 7 etc -proc dataPerChunk(T: type): int = +template dataPerChunk(T: type): int = # How many data items fit in a chunk - when T is bool|SomeUnsignedInt: # BasicType + when T is BasicType: bytesPerChunk div sizeof(T) else: 1 @@ -39,11 +44,6 @@ template layer*(vIdx: int64): int = log2trunc(vIdx.uint64).int type - UintN* = SomeUnsignedInt # TODO: Add StUint here - BasicType* = bool|UintN - - Limit* = int64 - List*[T; maxLen: static Limit] = distinct seq[T] BitList*[maxLen: static Limit] = distinct BitSeq