Fix serialization of deposits

This commit is contained in:
Mamy André-Ratsimbazafy 2020-03-12 02:11:48 +01:00 committed by tersec
parent 47ccae4ad6
commit 2aae54a15f
2 changed files with 12 additions and 22 deletions

View File

@ -275,42 +275,32 @@ template hash*(x: BlsCurveType): Hash =
# ----------------------------------------------------------------------
proc writeValue*(writer: var JsonWriter, value: ValidatorPubKey) {.inline.} =
when value is BlsValue:
doAssert value.kind == Real
writer.writeValue($value.blsValue)
else:
writer.writeValue($value)
writer.writeValue(value.blsValue.toHex())
proc readValue*(reader: var JsonReader, value: var ValidatorPubKey) {.inline.} =
value.initFromBytes(fromHex reader.readValue(string))
proc writeValue*(writer: var JsonWriter, value: ValidatorSig) {.inline.} =
when value is BlsValue:
if value.kind == Real:
writer.writeValue($value.blsValue)
writer.writeValue(value.blsValue.toHex())
else:
# Workaround: https://github.com/status-im/nim-beacon-chain/issues/374
let asHex = toHex(value.blob, true)
let asHex = value.blob.toHex(lowercase = true)
# echo "[Warning] writing raw opaque signature: ", asHex
writer.writeValue(asHex)
else:
writer.writeValue($value)
proc readValue*(reader: var JsonReader, value: var ValidatorSig) {.inline.} =
value.initFromBytes(fromHex reader.readValue(string))
proc writeValue*(writer: var JsonWriter, value: ValidatorPrivKey) {.inline.} =
when value is BlsValue:
doAssert value.kind == Real
writer.writeValue($value.blsValue)
else:
writer.writeValue($value)
writer.writeValue(value.toHex())
proc readValue*(reader: var JsonReader, value: var ValidatorPrivKey) {.inline.} =
value.initFromBytes(fromHex reader.readValue(string))
proc writeValue*(writer: var JsonWriter, value: PublicKey) {.inline.} =
writer.writeValue($value)
writer.writeValue(value.toHex())
proc readValue*(reader: var JsonReader, value: var PublicKey) {.inline.} =
let hex = reader.readValue(string)
@ -318,7 +308,7 @@ proc readValue*(reader: var JsonReader, value: var PublicKey) {.inline.} =
doAssert ok, "Invalid public key: " & hex
proc writeValue*(writer: var JsonWriter, value: Signature) {.inline.} =
writer.writeValue($value)
writer.writeValue(value.toHex())
proc readValue*(reader: var JsonReader, value: var Signature) {.inline.} =
let hex = reader.readValue(string)

View File

@ -49,7 +49,7 @@ proc generateDeposits*(totalValidators: int,
let dp = makeDeposit(pubKey, privKey)
writeTextFile(privKeyFn, $privKey)
writeTextFile(privKeyFn, privKey.toHex())
writeFile(depositFn, dp)
result.add(dp)