Skip to content

Commit

Permalink
Comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
yglukhov committed Mar 4, 2019
1 parent 4c31f50 commit 9ea0bf4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
13 changes: 8 additions & 5 deletions beacon_chain/beacon_chain_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions beacon_chain/spec/crypto.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 9ea0bf4

Please sign in to comment.