2020-05-22 17:04:52 +00:00
|
|
|
import
|
|
|
|
# Standard library
|
|
|
|
tables, json,
|
2020-06-03 13:52:02 +00:00
|
|
|
|
2020-05-22 17:04:52 +00:00
|
|
|
# Nimble packages
|
2020-06-03 13:52:02 +00:00
|
|
|
stew/byteutils, ssz/types,
|
2020-05-22 17:04:52 +00:00
|
|
|
json_rpc/jsonmarshal,
|
|
|
|
|
|
|
|
# Local modules
|
2020-06-03 13:52:02 +00:00
|
|
|
spec/[datatypes, crypto]
|
2020-05-22 17:04:52 +00:00
|
|
|
|
|
|
|
proc fromJson*(n: JsonNode, argName: string, result: var ValidatorPubKey) =
|
|
|
|
result = ValidatorPubKey.fromHex(n.getStr()).tryGet()
|
|
|
|
|
|
|
|
proc `%`*(pubkey: ValidatorPubKey): JsonNode =
|
|
|
|
result = newJString($pubkey)
|
|
|
|
|
|
|
|
proc fromJson*(n: JsonNode, argName: string, result: var List) =
|
|
|
|
fromJson(n, argName, asSeq result)
|
|
|
|
|
|
|
|
proc `%`*(list: List): JsonNode = %(asSeq(list))
|
|
|
|
|
|
|
|
proc fromJson*(n: JsonNode, argName: string, result: var BitList) =
|
|
|
|
fromJson(n, argName, seq[byte](BitSeq(result)))
|
|
|
|
|
|
|
|
proc `%`*(bitlist: BitList): JsonNode = %(seq[byte](BitSeq(bitlist)))
|
|
|
|
|
|
|
|
proc fromJson*(n: JsonNode, argName: string, result: var ValidatorSig) =
|
|
|
|
result = ValidatorSig.fromHex(n.getStr()).tryGet()
|
|
|
|
|
|
|
|
proc `%`*(value: ValidatorSig): JsonNode =
|
|
|
|
result = newJString($value)
|
|
|
|
|
2020-05-27 17:06:28 +00:00
|
|
|
proc fromJson*(n: JsonNode, argName: string, result: var Version) =
|
|
|
|
hexToByteArray(n.getStr(), array[4, byte](result))
|
|
|
|
|
|
|
|
proc `%`*(value: Version): JsonNode =
|
|
|
|
result = newJString($value)
|
|
|
|
|
2020-05-22 17:04:52 +00:00
|
|
|
template genFromJsonForIntType(t: untyped) =
|
|
|
|
proc fromJson*(n: JsonNode, argName: string, result: var t) =
|
|
|
|
n.kind.expect(JInt, argName)
|
|
|
|
result = n.getInt().t
|
|
|
|
|
|
|
|
genFromJsonForIntType(Epoch)
|
|
|
|
genFromJsonForIntType(Slot)
|
|
|
|
genFromJsonForIntType(CommitteeIndex)
|
|
|
|
|
|
|
|
proc `%`*(value: CommitteeIndex): JsonNode =
|
|
|
|
result = newJInt(value.int)
|