add section headers for REST serialization (#4210)

Adds missing REST serialization sections and makes them consistent.
This commit is contained in:
Etan Kissling 2022-10-04 00:29:07 +02:00 committed by GitHub
parent 231eb8a590
commit 83cd104d07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -464,6 +464,7 @@ proc readValue*(reader: var JsonReader[RestJson], value: var uint64) {.
else: else:
reader.raiseUnexpectedValue($res.error() & ": " & svalue) reader.raiseUnexpectedValue($res.error() & ": " & svalue)
## uint8
proc writeValue*(w: var JsonWriter[RestJson], value: uint8) {. proc writeValue*(w: var JsonWriter[RestJson], value: uint8) {.
raises: [IOError, Defect].} = raises: [IOError, Defect].} =
writeValue(w, Base10.toString(value)) writeValue(w, Base10.toString(value))
@ -477,6 +478,7 @@ proc readValue*(reader: var JsonReader[RestJson], value: var uint8) {.
else: else:
reader.raiseUnexpectedValue($res.error() & ": " & svalue) reader.raiseUnexpectedValue($res.error() & ": " & svalue)
## JustificationBits
proc writeValue*(w: var JsonWriter[RestJson], value: JustificationBits) {. proc writeValue*(w: var JsonWriter[RestJson], value: JustificationBits) {.
raises: [IOError, Defect].} = raises: [IOError, Defect].} =
w.writeValue hexOriginal([uint8(value)]) w.writeValue hexOriginal([uint8(value)])
@ -579,6 +581,7 @@ proc readValue*(reader: var JsonReader[RestJson], value: var ValidatorIndex)
else: else:
reader.raiseUnexpectedValue($res.error()) reader.raiseUnexpectedValue($res.error())
## IndexInSyncCommittee
proc writeValue*(writer: var JsonWriter[RestJson], value: IndexInSyncCommittee) proc writeValue*(writer: var JsonWriter[RestJson], value: IndexInSyncCommittee)
{.raises: [IOError, Defect].} = {.raises: [IOError, Defect].} =
writeValue(writer, Base10.toString(distinctBase(value))) writeValue(writer, Base10.toString(distinctBase(value)))
@ -778,6 +781,7 @@ proc writeValue*(writer: var JsonWriter[RestJson], value: Eth1Address) {.
raises: [IOError, Defect].} = raises: [IOError, Defect].} =
writeValue(writer, hexOriginal(distinctBase(value))) writeValue(writer, hexOriginal(distinctBase(value)))
## GraffitiBytes
proc writeValue*(writer: var JsonWriter[RestJson], value: GraffitiBytes) proc writeValue*(writer: var JsonWriter[RestJson], value: GraffitiBytes)
{.raises: [IOError, Defect].} = {.raises: [IOError, Defect].} =
writeValue(writer, hexOriginal(distinctBase(value))) writeValue(writer, hexOriginal(distinctBase(value)))
@ -789,7 +793,7 @@ proc readValue*(reader: var JsonReader[RestJson], T: type GraffitiBytes): T
except ValueError as err: except ValueError as err:
reader.raiseUnexpectedValue err.msg reader.raiseUnexpectedValue err.msg
## Version ## Version | ForkDigest | DomainType | GraffitiBytes
proc readValue*( proc readValue*(
reader: var JsonReader[RestJson], reader: var JsonReader[RestJson],
value: var (Version | ForkDigest | DomainType | GraffitiBytes)) {. value: var (Version | ForkDigest | DomainType | GraffitiBytes)) {.
@ -1442,7 +1446,7 @@ proc writeValue*(writer: var JsonWriter[RestJson], value: ForkedHashedBeaconStat
writer.writeField("data", value.bellatrixData.data) writer.writeField("data", value.bellatrixData.data)
writer.endRecord() writer.endRecord()
# Web3SignerRequest ## Web3SignerRequest
proc writeValue*(writer: var JsonWriter[RestJson], proc writeValue*(writer: var JsonWriter[RestJson],
value: Web3SignerRequest) {. value: Web3SignerRequest) {.
raises: [IOError, Defect].} = raises: [IOError, Defect].} =
@ -2103,6 +2107,7 @@ proc readValue*(reader: var JsonReader[RestJson],
keystores: keystores, passwords: passwords, slashing_protection: slashing keystores: keystores, passwords: passwords, slashing_protection: slashing
) )
## RestActivityItem
proc writeValue*(writer: var JsonWriter[RestJson], proc writeValue*(writer: var JsonWriter[RestJson],
value: RestActivityItem) {. value: RestActivityItem) {.
raises: [IOError, Defect].} = raises: [IOError, Defect].} =
@ -2149,6 +2154,7 @@ proc readValue*(reader: var JsonReader[RestJson],
value = RestActivityItem(index: index.get(), epoch: epoch.get(), value = RestActivityItem(index: index.get(), epoch: epoch.get(),
active: active.get()) active: active.get())
## HeadChangeInfoObject
proc writeValue*(writer: var JsonWriter[RestJson], proc writeValue*(writer: var JsonWriter[RestJson],
value: HeadChangeInfoObject) {. value: HeadChangeInfoObject) {.
raises: [IOError, Defect].} = raises: [IOError, Defect].} =
@ -2165,6 +2171,7 @@ proc writeValue*(writer: var JsonWriter[RestJson],
writer.writeField("execution_optimistic", value.optimistic.get()) writer.writeField("execution_optimistic", value.optimistic.get())
writer.endRecord() writer.endRecord()
## ReorgInfoObject
proc writeValue*(writer: var JsonWriter[RestJson], proc writeValue*(writer: var JsonWriter[RestJson],
value: ReorgInfoObject) {. value: ReorgInfoObject) {.
raises: [IOError, Defect].} = raises: [IOError, Defect].} =
@ -2179,6 +2186,7 @@ proc writeValue*(writer: var JsonWriter[RestJson],
writer.writeField("execution_optimistic", value.optimistic.get()) writer.writeField("execution_optimistic", value.optimistic.get())
writer.endRecord() writer.endRecord()
## FinalizationInfoObject
proc writeValue*(writer: var JsonWriter[RestJson], proc writeValue*(writer: var JsonWriter[RestJson],
value: FinalizationInfoObject) {. value: FinalizationInfoObject) {.
raises: [IOError, Defect].} = raises: [IOError, Defect].} =
@ -2190,6 +2198,7 @@ proc writeValue*(writer: var JsonWriter[RestJson],
writer.writeField("execution_optimistic", value.optimistic.get()) writer.writeField("execution_optimistic", value.optimistic.get())
writer.endRecord() writer.endRecord()
## EventBeaconBlockObject
proc writeValue*(writer: var JsonWriter[RestJson], proc writeValue*(writer: var JsonWriter[RestJson],
value: EventBeaconBlockObject) {. value: EventBeaconBlockObject) {.
raises: [IOError, Defect].} = raises: [IOError, Defect].} =
@ -2200,6 +2209,7 @@ proc writeValue*(writer: var JsonWriter[RestJson],
writer.writeField("execution_optimistic", value.optimistic.get()) writer.writeField("execution_optimistic", value.optimistic.get())
writer.endRecord() writer.endRecord()
## RestSyncInfo
proc writeValue*(writer: var JsonWriter[RestJson], proc writeValue*(writer: var JsonWriter[RestJson],
value: RestSyncInfo) {. value: RestSyncInfo) {.
raises: [IOError, Defect].} = raises: [IOError, Defect].} =