remove some unused rest serialization code (#6056)

This commit is contained in:
Jacek Sieka 2024-03-09 11:38:24 +01:00 committed by GitHub
parent 65c47c7769
commit 2d519ac715
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -478,8 +478,6 @@ proc prepareJsonResponse*(t: typedesc[RestApiResponse], d: auto): seq[byte] =
writer.writeField("data", d) writer.writeField("data", d)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
res res
@ -499,8 +497,6 @@ proc prepareJsonStringResponse*[T: SomeForkedLightClientObject](
writer.writeField("data", forkyObject) writer.writeField("data", forkyObject)
writer.endRecord() writer.endRecord()
stream.getOutput(string) stream.getOutput(string)
except SerializationError:
default
except IOError: except IOError:
default default
res res
@ -514,8 +510,6 @@ proc prepareJsonStringResponse*(t: typedesc[RestApiResponse], d: auto): string =
var writer = JsonWriter[RestJson].init(stream) var writer = JsonWriter[RestJson].init(stream)
writer.writeValue(d) writer.writeValue(d)
stream.getOutput(string) stream.getOutput(string)
except SerializationError:
default
except IOError: except IOError:
default default
res res
@ -536,8 +530,6 @@ proc jsonResponseWRoot*(t: typedesc[RestApiResponse], data: auto,
writer.writeField("data", data) writer.writeField("data", data)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json") RestApiResponse.response(res, Http200, "application/json")
@ -553,8 +545,6 @@ proc jsonResponse*(t: typedesc[RestApiResponse], data: auto): RestApiResponse =
writer.writeField("data", data) writer.writeField("data", data)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json") RestApiResponse.response(res, Http200, "application/json")
@ -580,8 +570,6 @@ proc jsonResponseBlock*(t: typedesc[RestApiResponse],
writer.writeField("data", data) writer.writeField("data", data)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json", headers = headers) RestApiResponse.response(res, Http200, "application/json", headers = headers)
@ -607,8 +595,6 @@ proc jsonResponseBlock*(t: typedesc[RestApiResponse],
writer.writeField("data", forkyBlck) writer.writeField("data", forkyBlck)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json", headers = headers) RestApiResponse.response(res, Http200, "application/json", headers = headers)
@ -632,8 +618,6 @@ proc jsonResponseState*(t: typedesc[RestApiResponse],
writer.writeField("data", forkyState.data) writer.writeField("data", forkyState.data)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json", headers = headers) RestApiResponse.response(res, Http200, "application/json", headers = headers)
@ -652,8 +636,6 @@ proc jsonResponseWOpt*(t: typedesc[RestApiResponse], data: auto,
writer.writeField("data", data) writer.writeField("data", data)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json") RestApiResponse.response(res, Http200, "application/json")
@ -674,8 +656,6 @@ proc jsonResponseFinalized*(t: typedesc[RestApiResponse], data: auto,
writer.writeField("data", data) writer.writeField("data", data)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json") RestApiResponse.response(res, Http200, "application/json")
@ -695,8 +675,6 @@ proc jsonResponseWVersion*(t: typedesc[RestApiResponse], data: auto,
writer.writeField("data", data) writer.writeField("data", data)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json", headers = headers) RestApiResponse.response(res, Http200, "application/json", headers = headers)
@ -718,8 +696,6 @@ proc jsonResponseVersioned*[T: SomeForkedLightClientObject](
writer.writeField("data", forkyObject) writer.writeField("data", forkyObject)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json") RestApiResponse.response(res, Http200, "application/json")
@ -734,8 +710,6 @@ proc jsonResponsePlain*(t: typedesc[RestApiResponse],
var writer = JsonWriter[RestJson].init(stream) var writer = JsonWriter[RestJson].init(stream)
writer.writeValue(data) writer.writeValue(data)
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json") RestApiResponse.response(res, Http200, "application/json")
@ -750,8 +724,6 @@ proc jsonResponsePlain*(t: typedesc[RestApiResponse],
var writer = JsonWriter[RestJson].init(stream) var writer = JsonWriter[RestJson].init(stream)
writer.writeValue(data) writer.writeValue(data)
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json", headers = headers) RestApiResponse.response(res, Http200, "application/json", headers = headers)
@ -769,8 +741,6 @@ proc jsonResponseWMeta*(t: typedesc[RestApiResponse],
writer.writeField("meta", meta) writer.writeField("meta", meta)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/json") RestApiResponse.response(res, Http200, "application/json")
@ -788,8 +758,6 @@ proc jsonMsgResponse*(t: typedesc[RestApiResponse],
writer.writeField("message", msg) writer.writeField("message", msg)
writer.endRecord() writer.endRecord()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(data, Http200, "application/json") RestApiResponse.response(data, Http200, "application/json")
@ -807,8 +775,6 @@ proc jsonError*(t: typedesc[RestApiResponse], status: HttpCode = Http200,
writer.writeField("message", msg) writer.writeField("message", msg)
writer.endRecord() writer.endRecord()
stream.getOutput(string) stream.getOutput(string)
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.error(status, data, "application/json") RestApiResponse.error(status, data, "application/json")
@ -828,8 +794,6 @@ proc jsonError*(t: typedesc[RestApiResponse], status: HttpCode = Http200,
writer.writeField("stacktraces", [stacktrace]) writer.writeField("stacktraces", [stacktrace])
writer.endRecord() writer.endRecord()
stream.getOutput(string) stream.getOutput(string)
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.error(status, data, "application/json") RestApiResponse.error(status, data, "application/json")
@ -849,8 +813,6 @@ proc jsonError*(t: typedesc[RestApiResponse], status: HttpCode = Http200,
writer.writeField("stacktraces", stacktraces) writer.writeField("stacktraces", stacktraces)
writer.endRecord() writer.endRecord()
stream.getOutput(string) stream.getOutput(string)
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.error(status, data, "application/json") RestApiResponse.error(status, data, "application/json")
@ -870,8 +832,6 @@ proc jsonError*(t: typedesc[RestApiResponse],
writer.writeField("stacktraces", rmsg.stacktraces) writer.writeField("stacktraces", rmsg.stacktraces)
writer.endRecord() writer.endRecord()
stream.getOutput(string) stream.getOutput(string)
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.error(rmsg.code.toHttpCode().get(), data, "application/json") RestApiResponse.error(rmsg.code.toHttpCode().get(), data, "application/json")
@ -891,8 +851,6 @@ proc jsonErrorList*(t: typedesc[RestApiResponse],
writer.writeField("failures", failures) writer.writeField("failures", failures)
writer.endRecord() writer.endRecord()
stream.getOutput(string) stream.getOutput(string)
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.error(status, data, "application/json") RestApiResponse.error(status, data, "application/json")
@ -915,8 +873,6 @@ proc sszResponseVersioned*[T: SomeForkedLightClientObject](
writer.writeValue forkyUpdate writer.writeValue forkyUpdate
cursor.finalWrite (stream.pos - initPos).uint64.toBytesLE() cursor.finalWrite (stream.pos - initPos).uint64.toBytesLE()
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/octet-stream") RestApiResponse.response(res, Http200, "application/octet-stream")
@ -938,8 +894,6 @@ proc sszResponse*(t: typedesc[RestApiResponse], data: auto,
var writer = SszWriter.init(stream) var writer = SszWriter.init(stream)
writer.writeValue(data) writer.writeValue(data)
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/octet-stream", RestApiResponse.response(res, Http200, "application/octet-stream",
@ -955,8 +909,6 @@ proc sszResponse*(t: typedesc[RestApiResponse], data: auto,
var writer = SszWriter.init(stream) var writer = SszWriter.init(stream)
writer.writeValue(data) writer.writeValue(data)
stream.getOutput(seq[byte]) stream.getOutput(seq[byte])
except SerializationError:
default
except IOError: except IOError:
default default
RestApiResponse.response(res, Http200, "application/octet-stream", RestApiResponse.response(res, Http200, "application/octet-stream",
@ -1483,68 +1435,62 @@ proc readValue*[BlockType: ProduceBlockResponseV2](
of ConsensusFork.Phase0: of ConsensusFork.Phase0:
let res = let res =
try: try:
Opt.some(RestJson.decode(string(data.get()), RestJson.decode(string(data.get()),
phase0.BeaconBlock, phase0.BeaconBlock,
requireAllFields = true, requireAllFields = true,
allowUnknownFields = true)) allowUnknownFields = true)
except SerializationError: except SerializationError:
Opt.none(phase0.BeaconBlock) reader.raiseUnexpectedValue("Incorrect phase0 block format")
if res.isNone():
reader.raiseUnexpectedValue("Incorrect phase0 block format")
value = ProduceBlockResponseV2(kind: ConsensusFork.Phase0, value = ProduceBlockResponseV2(kind: ConsensusFork.Phase0,
phase0Data: res.get()) phase0Data: res)
of ConsensusFork.Altair: of ConsensusFork.Altair:
let res = let res =
try: try:
Opt.some(RestJson.decode(string(data.get()), RestJson.decode(string(data.get()),
altair.BeaconBlock, altair.BeaconBlock,
requireAllFields = true, requireAllFields = true,
allowUnknownFields = true)) allowUnknownFields = true)
except SerializationError: except SerializationError:
Opt.none(altair.BeaconBlock) reader.raiseUnexpectedValue("Incorrect altair block format")
if res.isNone():
reader.raiseUnexpectedValue("Incorrect altair block format")
value = ProduceBlockResponseV2(kind: ConsensusFork.Altair, value = ProduceBlockResponseV2(kind: ConsensusFork.Altair,
altairData: res.get()) altairData: res)
of ConsensusFork.Bellatrix: of ConsensusFork.Bellatrix:
let res = let res =
try: try:
Opt.some(RestJson.decode(string(data.get()), RestJson.decode(string(data.get()),
bellatrix.BeaconBlock, bellatrix.BeaconBlock,
requireAllFields = true, requireAllFields = true,
allowUnknownFields = true)) allowUnknownFields = true)
except SerializationError: except SerializationError:
Opt.none(bellatrix.BeaconBlock) reader.raiseUnexpectedValue("Incorrect bellatrix block format")
if res.isNone():
reader.raiseUnexpectedValue("Incorrect bellatrix block format")
value = ProduceBlockResponseV2(kind: ConsensusFork.Bellatrix, value = ProduceBlockResponseV2(kind: ConsensusFork.Bellatrix,
bellatrixData: res.get()) bellatrixData: res)
of ConsensusFork.Capella: of ConsensusFork.Capella:
let res = let res =
try: try:
Opt.some(RestJson.decode(string(data.get()), RestJson.decode(string(data.get()),
capella.BeaconBlock, capella.BeaconBlock,
requireAllFields = true, requireAllFields = true,
allowUnknownFields = true)) allowUnknownFields = true)
except SerializationError: except SerializationError:
Opt.none(capella.BeaconBlock) reader.raiseUnexpectedValue("Incorrect capella block format")
if res.isNone():
reader.raiseUnexpectedValue("Incorrect capella block format")
value = ProduceBlockResponseV2(kind: ConsensusFork.Capella, value = ProduceBlockResponseV2(kind: ConsensusFork.Capella,
capellaData: res.get()) capellaData: res)
of ConsensusFork.Deneb: of ConsensusFork.Deneb:
let res = let res =
try: try:
Opt.some(RestJson.decode(string(data.get()), RestJson.decode(string(data.get()),
deneb.BlockContents, deneb.BlockContents,
requireAllFields = true, requireAllFields = true,
allowUnknownFields = true)) allowUnknownFields = true)
except SerializationError: except SerializationError:
Opt.none(deneb.BlockContents) reader.raiseUnexpectedValue("Incorrect deneb block format")
if res.isNone():
reader.raiseUnexpectedValue("Incorrect deneb block format")
value = ProduceBlockResponseV2(kind: ConsensusFork.Deneb, value = ProduceBlockResponseV2(kind: ConsensusFork.Deneb,
denebData: res.get()) denebData: res)
proc readValue*[BlockType: ForkedBlindedBeaconBlock]( proc readValue*[BlockType: ForkedBlindedBeaconBlock](
reader: var JsonReader[RestJson], reader: var JsonReader[RestJson],
@ -1571,6 +1517,7 @@ proc readValue*[BlockType: ForkedBlindedBeaconBlock](
except SerializationError as exc: except SerializationError as exc:
reader.raiseUnexpectedValue("Incorrect phase0 block format, [" & reader.raiseUnexpectedValue("Incorrect phase0 block format, [" &
exc.formatMsg("BlindedBlock") & "]") exc.formatMsg("BlindedBlock") & "]")
value = ForkedBlindedBeaconBlock(kind: ConsensusFork.Phase0, value = ForkedBlindedBeaconBlock(kind: ConsensusFork.Phase0,
phase0Data: res) phase0Data: res)
of ConsensusFork.Altair: of ConsensusFork.Altair:
@ -1625,20 +1572,20 @@ proc readValue*[BlockType: Web3SignerForkedBeaconBlock](
prepareForkedBlockReading(BlockType, reader, version, data, blinded, prepareForkedBlockReading(BlockType, reader, version, data, blinded,
payloadValue, blockValue) payloadValue, blockValue)
let res =
try:
Opt.some(RestJson.decode(string(data.get()),
BeaconBlockHeader,
requireAllFields = true,
allowUnknownFields = true))
except SerializationError:
Opt.none(BeaconBlockHeader)
if res.isNone():
reader.raiseUnexpectedValue("Incorrect block header format")
if version.get() <= ConsensusFork.Altair: if version.get() <= ConsensusFork.Altair:
reader.raiseUnexpectedValue( reader.raiseUnexpectedValue(
"Web3Signer implementation supports Bellatrix and newer") "Web3Signer implementation supports Bellatrix and newer")
value = Web3SignerForkedBeaconBlock(kind: version.get(), data: res.get())
let res =
try:
RestJson.decode(string(data.get()),
BeaconBlockHeader,
requireAllFields = true,
allowUnknownFields = true)
except SerializationError:
reader.raiseUnexpectedValue("Incorrect block header format")
value = Web3SignerForkedBeaconBlock(kind: version.get(), data: res)
proc writeValue*[BlockType: Web3SignerForkedBeaconBlock]( proc writeValue*[BlockType: Web3SignerForkedBeaconBlock](
writer: var JsonWriter[RestJson], value: BlockType) {.raises: [IOError].} = writer: var JsonWriter[RestJson], value: BlockType) {.raises: [IOError].} =
@ -2275,63 +2222,58 @@ proc readValue*(reader: var JsonReader[RestJson],
of ConsensusFork.Phase0: of ConsensusFork.Phase0:
let res = let res =
try: try:
Opt.some(RestJson.decode(string(data.get()), RestJson.decode(string(data.get()),
phase0.SignedBeaconBlock, phase0.SignedBeaconBlock,
requireAllFields = true, requireAllFields = true,
allowUnknownFields = true)) allowUnknownFields = true)
except SerializationError: except SerializationError:
Opt.none(phase0.SignedBeaconBlock) reader.raiseUnexpectedValue("Incorrect phase0 block format")
if res.isNone():
reader.raiseUnexpectedValue("Incorrect phase0 block format") value = ForkedSignedBeaconBlock.init(res)
value = ForkedSignedBeaconBlock.init(res.get())
of ConsensusFork.Altair: of ConsensusFork.Altair:
let res = let res =
try: try:
Opt.some(RestJson.decode(string(data.get()), RestJson.decode(string(data.get()),
altair.SignedBeaconBlock, altair.SignedBeaconBlock,
requireAllFields = true, requireAllFields = true,
allowUnknownFields = true)) allowUnknownFields = true)
except SerializationError: except SerializationError:
Opt.none(altair.SignedBeaconBlock) reader.raiseUnexpectedValue("Incorrect altair block format")
if res.isNone():
reader.raiseUnexpectedValue("Incorrect altair block format") value = ForkedSignedBeaconBlock.init(res)
value = ForkedSignedBeaconBlock.init(res.get())
of ConsensusFork.Bellatrix: of ConsensusFork.Bellatrix:
let res = let res =
try: try:
Opt.some(RestJson.decode(string(data.get()), RestJson.decode(string(data.get()),
bellatrix.SignedBeaconBlock, bellatrix.SignedBeaconBlock,
requireAllFields = true, requireAllFields = true,
allowUnknownFields = true)) allowUnknownFields = true)
except SerializationError: except SerializationError:
Opt.none(bellatrix.SignedBeaconBlock) reader.raiseUnexpectedValue("Incorrect bellatrix block format")
if res.isNone():
reader.raiseUnexpectedValue("Incorrect bellatrix block format") value = ForkedSignedBeaconBlock.init(res)
value = ForkedSignedBeaconBlock.init(res.get())
of ConsensusFork.Capella: of ConsensusFork.Capella:
let res = let res =
try: try:
Opt.some(RestJson.decode(string(data.get()), RestJson.decode(string(data.get()),
capella.SignedBeaconBlock, capella.SignedBeaconBlock,
requireAllFields = true, requireAllFields = true,
allowUnknownFields = true)) allowUnknownFields = true)
except SerializationError: except SerializationError:
Opt.none(capella.SignedBeaconBlock) reader.raiseUnexpectedValue("Incorrect capella block format")
if res.isNone():
reader.raiseUnexpectedValue("Incorrect capella block format") value = ForkedSignedBeaconBlock.init(res)
value = ForkedSignedBeaconBlock.init(res.get())
of ConsensusFork.Deneb: of ConsensusFork.Deneb:
let res = let res =
try: try:
Opt.some(RestJson.decode(string(data.get()), RestJson.decode(string(data.get()),
deneb.SignedBeaconBlock, deneb.SignedBeaconBlock,
requireAllFields = true, requireAllFields = true,
allowUnknownFields = true)) allowUnknownFields = true)
except SerializationError: except SerializationError:
Opt.none(deneb.SignedBeaconBlock) reader.raiseUnexpectedValue("Incorrect deneb block format")
if res.isNone():
reader.raiseUnexpectedValue("Incorrect deneb block format") value = ForkedSignedBeaconBlock.init(res)
value = ForkedSignedBeaconBlock.init(res.get())
withBlck(value): withBlck(value):
forkyBlck.root = hash_tree_root(forkyBlck.message) forkyBlck.root = hash_tree_root(forkyBlck.message)