Add some missing RLP serialization routines (#144)

* Add some missing RLP serialization routines
This commit is contained in:
zah 2019-02-28 23:50:21 +02:00 committed by Jacek Sieka
parent 1cfea240ed
commit 859aa327cb
2 changed files with 19 additions and 27 deletions

View File

@ -47,10 +47,10 @@
import import
sequtils, sequtils,
hashes, hashes,
blscurve, json_serialization blscurve, json_serialization, eth/rlp
export export
json_serialization json_serialization, rlp
export blscurve.init, blscurve.getBytes, blscurve.combine, blscurve.`$`, blscurve.`==` export blscurve.init, blscurve.getBytes, blscurve.combine, blscurve.`$`, blscurve.`==`
@ -127,3 +127,17 @@ proc readValue*(reader: var JsonReader, value: var ValidatorPrivKey) {.inline.}
value = SigKey.init(reader.readValue(string)) value = SigKey.init(reader.readValue(string))
proc newPrivKey*(): ValidatorPrivKey = SigKey.random() proc newPrivKey*(): ValidatorPrivKey = SigKey.random()
# RLP serialization (TODO: remove if no longer necessary)
proc append*(writer: var RlpWriter, value: ValidatorPubKey) =
writer.append value.getBytes()
proc read*(rlp: var Rlp, T: type ValidatorPubKey): T {.inline.} =
ValidatorPubKey.init rlp.toBytes.toOpenArray
proc append*(writer: var RlpWriter, value: ValidatorSig) =
writer.append value.getBytes()
proc read*(rlp: var Rlp, T: type ValidatorSig): T {.inline.} =
ValidatorSig.init rlp.toBytes.toOpenArray

View File

@ -482,29 +482,6 @@ type
# TODO: not in spec # TODO: not in spec
CrosslinkCommittee* = tuple[committee: seq[ValidatorIndex], shard: uint64] CrosslinkCommittee* = tuple[committee: seq[ValidatorIndex], shard: uint64]
when true:
# TODO: Remove these once RLP serialization is no longer used
import nimcrypto, eth/rlp, json_serialization
export append, read, json_serialization
proc append*(rlpWriter: var RlpWriter, value: ValidatorPubKey) =
discard
proc read*(rlp: var Rlp, T: type ValidatorPubKey): T {.inline.} =
discard
proc append*(rlpWriter: var RlpWriter, value: ValidatorIndex) =
discard
proc read*(rlp: var Rlp, T: type ValidatorIndex): T {.inline.} =
discard
proc append*(rlpWriter: var RlpWriter, value: ValidatorSig) =
discard
proc read*(rlp: var Rlp, T: type ValidatorSig): T {.inline.} =
discard
func shortValidatorKey*(state: BeaconState, validatorIdx: int): string = func shortValidatorKey*(state: BeaconState, validatorIdx: int): string =
($state.validator_registry[validatorIdx].pubkey)[0..7] ($state.validator_registry[validatorIdx].pubkey)[0..7]
@ -514,6 +491,7 @@ func humaneSlotNum*(s: Slot): Slot =
func humaneEpochNum*(e: Epoch): Epoch = func humaneEpochNum*(e: Epoch): Epoch =
e - GENESIS_EPOCH e - GENESIS_EPOCH
export import nimcrypto, eth/rlp, json_serialization
writeValue, readValue export json_serialization, rlp
export writeValue, readValue, append, read