mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-22 19:28:20 +00:00
move EpochParticipationFlags
serialization to others (#4167)
The REST `writeValue/readValue` serialization functions are grouped up with the exception of `EpochParticipationFlags`. Moving that to others.
This commit is contained in:
parent
77ea188c92
commit
7ac95c6ee7
@ -145,30 +145,6 @@ when (NimMajor, NimMinor) < (1, 4):
|
|||||||
else:
|
else:
|
||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
proc writeValue*(writer: var JsonWriter[RestJson],
|
|
||||||
epochFlags: EpochParticipationFlags)
|
|
||||||
{.raises: [IOError, Defect].} =
|
|
||||||
for e in writer.stepwiseArrayCreation(epochFlags.asHashList):
|
|
||||||
writer.writeValue $e
|
|
||||||
|
|
||||||
proc readValue*(reader: var JsonReader[RestJson],
|
|
||||||
epochFlags: var EpochParticipationFlags)
|
|
||||||
{.raises: [SerializationError, IOError, Defect].} =
|
|
||||||
# Please note that this function won't compute the cached hash tree roots
|
|
||||||
# immediately. They will be computed on the first HTR attempt.
|
|
||||||
|
|
||||||
for e in reader.readArray(string):
|
|
||||||
let parsed = try:
|
|
||||||
parseBiggestUInt(e)
|
|
||||||
except ValueError as err:
|
|
||||||
reader.raiseUnexpectedValue("A string-encoded 8-bit usigned integer value expected")
|
|
||||||
|
|
||||||
if parsed > uint8.high:
|
|
||||||
reader.raiseUnexpectedValue("The usigned integer value should fit in 8 bits")
|
|
||||||
|
|
||||||
if not epochFlags.data.add(uint8(parsed)):
|
|
||||||
reader.raiseUnexpectedValue("The participation flags list size exceeds limit")
|
|
||||||
|
|
||||||
proc prepareJsonResponse*(t: typedesc[RestApiResponse], d: auto): seq[byte] =
|
proc prepareJsonResponse*(t: typedesc[RestApiResponse], d: auto): seq[byte] =
|
||||||
let res =
|
let res =
|
||||||
block:
|
block:
|
||||||
@ -572,6 +548,34 @@ proc readValue*(reader: var JsonReader[RestJson], value: var Epoch) {.
|
|||||||
else:
|
else:
|
||||||
reader.raiseUnexpectedValue($res.error())
|
reader.raiseUnexpectedValue($res.error())
|
||||||
|
|
||||||
|
## EpochParticipationFlags
|
||||||
|
proc writeValue*(writer: var JsonWriter[RestJson],
|
||||||
|
epochFlags: EpochParticipationFlags)
|
||||||
|
{.raises: [IOError, Defect].} =
|
||||||
|
for e in writer.stepwiseArrayCreation(epochFlags.asHashList):
|
||||||
|
writer.writeValue $e
|
||||||
|
|
||||||
|
proc readValue*(reader: var JsonReader[RestJson],
|
||||||
|
epochFlags: var EpochParticipationFlags)
|
||||||
|
{.raises: [SerializationError, IOError, Defect].} =
|
||||||
|
# Please note that this function won't compute the cached hash tree roots
|
||||||
|
# immediately. They will be computed on the first HTR attempt.
|
||||||
|
|
||||||
|
for e in reader.readArray(string):
|
||||||
|
let parsed = try:
|
||||||
|
parseBiggestUInt(e)
|
||||||
|
except ValueError as err:
|
||||||
|
reader.raiseUnexpectedValue(
|
||||||
|
"A string-encoded 8-bit usigned integer value expected")
|
||||||
|
|
||||||
|
if parsed > uint8.high:
|
||||||
|
reader.raiseUnexpectedValue(
|
||||||
|
"The usigned integer value should fit in 8 bits")
|
||||||
|
|
||||||
|
if not epochFlags.data.add(uint8(parsed)):
|
||||||
|
reader.raiseUnexpectedValue(
|
||||||
|
"The participation flags list size exceeds limit")
|
||||||
|
|
||||||
## ValidatorIndex
|
## ValidatorIndex
|
||||||
proc writeValue*(writer: var JsonWriter[RestJson], value: ValidatorIndex)
|
proc writeValue*(writer: var JsonWriter[RestJson], value: ValidatorIndex)
|
||||||
{.raises: [IOError, Defect].} =
|
{.raises: [IOError, Defect].} =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user