Fix /api/eth/v1/validator/aggregate_and_proofs call

This commit is contained in:
cheatfate 2021-05-20 21:43:42 +03:00 committed by zah
parent 6869a1ad33
commit be5661eebc
1 changed files with 13 additions and 11 deletions

View File

@ -288,26 +288,28 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
# https://ethereum.github.io/eth2.0-APIs/#/Validator/publishAggregateAndProofs
router.api(MethodPost, "/api/eth/v1/validator/aggregate_and_proofs") do (
contentBody: Option[ContentBody]) -> RestApiResponse:
let payload =
let proofs =
block:
if contentBody.isNone():
return RestApiResponse.jsonError(Http400, EmptyRequestBodyError)
let dres = decodeBody(SignedAggregateAndProof, contentBody.get())
let dres = decodeBody(seq[SignedAggregateAndProof], contentBody.get())
if dres.isErr():
return RestApiResponse.jsonError(Http400,
InvalidAggregateAndProofObjectError,
$dres.error())
dres.get()
for item in proofs:
let wallTime = node.processor.getWallTime()
let res = await node.attestationPool.validateAggregate(
node.processor.batchCrypto, payload, wallTime
node.processor.batchCrypto, item, wallTime
)
if res.isErr():
return RestApiResponse.jsonError(Http400,
AggregateAndProofValidationError,
$res.error())
node.network.broadcast(node.topicAggregateAndProofs, payload)
node.network.broadcast(node.topicAggregateAndProofs, item)
return RestApiResponse.jsonError(Http200,
AggregateAndProofValidationSuccess)