Comments addressed

This commit is contained in:
Yuriy Glukhov 2019-03-04 13:50:26 +02:00
parent 4c31f50889
commit 9ea0bf4326
No known key found for this signature in database
GPG Key ID: 733560674BB43E6C
2 changed files with 12 additions and 11 deletions

View File

@ -18,11 +18,14 @@ type
func subkey(kind: DbKeyKind): array[1, byte] =
result[0] = byte ord(kind)
func subkey[T](kind: DbKeyKind, key: T): auto =
var res: array[sizeof(T) + 1, byte]
res[0] = byte ord(kind)
copyMem(addr res[1], unsafeAddr key, sizeof(key))
return res
func subkey[N: static int](kind: DbKeyKind, key: array[N, byte]):
array[N + 1, byte] =
result[0] = byte ord(kind)
result[1 .. ^1] = key
func subkey(kind: DbKeyKind, key: uint64): array[sizeof(key) + 1, byte] =
result[0] = byte ord(kind)
copyMem(addr result[1], unsafeAddr key, sizeof(key))
func subkey(kind: type BeaconState, key: Eth2Digest): auto =
subkey(kHashToState, key.data)

View File

@ -133,15 +133,13 @@ proc append*(writer: var RlpWriter, value: ValidatorPubKey) =
writer.append value.getBytes()
proc read*(rlp: var Rlp, T: type ValidatorPubKey): T {.inline.} =
let r = rlp.read(seq[byte])
if not init(result, r):
raise newException(Exception, "Could not init ValidatorPubKey from bytes")
result = ValidatorPubKey.init(rlp.toBytes.toOpenArray)
rlp.skipElem()
proc append*(writer: var RlpWriter, value: ValidatorSig) =
writer.append value.getBytes()
proc read*(rlp: var Rlp, T: type ValidatorSig): T {.inline.} =
let r = rlp.read(seq[byte])
if not init(result, r):
raise newException(Exception, "Could not init ValidatorSig from bytes")
result = ValidatorSig.init(rlp.toBytes.toOpenArray)
rlp.skipElem()