Fix /api/eth/v1/validator/duties/attester/{epoch} request body ValidatorIndex issues.

This commit is contained in:
cheatfate 2021-04-06 11:00:26 +03:00 committed by zah
parent c56cb0a485
commit d443801818
2 changed files with 34 additions and 2 deletions

View File

@ -151,6 +151,23 @@ proc readValue*(reader: var JsonReader[RestJson], value: var ValidatorIndex) {.
else:
reader.raiseUnexpectedValue($res.error())
## RestValidatorIndex
proc writeValue*(writer: var JsonWriter[RestJson],
value: RestValidatorIndex) {.
raises: [IOError, Defect].} =
writeValue(writer, Base10.toString(uint64(value)))
proc readValue*(reader: var JsonReader[RestJson],
value: var RestValidatorIndex) {.
raises: [IOError, SerializationError, Defect].} =
let svalue = reader.readValue(string)
let res = Base10.decode(uint64, svalue)
if res.isOk():
let v = res.get()
value = RestValidatorIndex(v)
else:
reader.raiseUnexpectedValue($res.error())
## CommitteeIndex
proc writeValue*(writer: var JsonWriter[RestJson], value: CommitteeIndex) {.
raises: [IOError, Defect].} =

View File

@ -48,11 +48,26 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
block:
if contentBody.isNone():
return RestApiResponse.jsonError(Http400, "Empty request's body")
let dres = decodeBody(seq[ValidatorIndex], contentBody.get())
let dres = decodeBody(seq[RestValidatorIndex], contentBody.get())
if dres.isErr():
return RestApiResponse.jsonError(Http400, "Unable to decode " &
"list of validator indexes", $dres.error())
dres.get()
var res: seq[ValidatorIndex]
let items = dres.get()
for item in items:
let vres = item.toValidatorIndex()
if vres.isErr():
case vres.error()
of ValidatorIndexError.TooHighValue:
return RestApiResponse.jsonError(Http400,
"Incorrect validator index value")
of ValidatorIndexError.UnsupportedValue:
return RestApiResponse.jsonError(Http500,
"Unsupported validator index value")
res.add(vres.get())
if len(res) == 0:
return RestApiResponse.jsonError(Http400, "Empty indexes list")
res
let qepoch =
block:
if epoch.isErr():