use of tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_ACCEPTED in project teku by ConsenSys.
the class PostBlock method handle.
@OpenApi(path = ROUTE, method = HttpMethod.POST, summary = "Publish a signed block", tags = { TAG_BEACON, TAG_VALIDATOR_REQUIRED }, requestBody = @OpenApiRequestBody(content = { @OpenApiContent(from = SignedBlock.class) }), description = "Submit a signed beacon block to the beacon node to be imported." + " The beacon node performs the required validation.", responses = { @OpenApiResponse(status = RES_OK, description = "Block has been successfully broadcast, validated and imported."), @OpenApiResponse(status = RES_ACCEPTED, description = "Block has been successfully broadcast, but failed validation and has not been imported."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Unable to parse request body."), @OpenApiResponse(status = RES_INTERNAL_ERROR, description = "Beacon node experienced an internal error."), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = "Beacon node is currently syncing.") })
@Override
public void handle(final Context ctx) throws Exception {
try {
if (syncDataProvider.isSyncing()) {
ctx.status(SC_SERVICE_UNAVAILABLE);
ctx.json(BadRequest.serviceUnavailable(jsonProvider));
return;
}
final SignedBeaconBlock signedBeaconBlock = validatorDataProvider.parseBlock(jsonProvider, ctx.body());
ctx.future(validatorDataProvider.submitSignedBlock(signedBeaconBlock).thenApplyChecked(validatorBlockResult -> handleResponseContext(ctx, validatorBlockResult)));
} catch (final JsonProcessingException ex) {
ctx.status(SC_BAD_REQUEST);
ctx.json(BadRequest.badRequest(jsonProvider, ex.getMessage()));
} catch (final Exception ex) {
LOG.error("Failed to post block due to internal error", ex);
ctx.status(SC_INTERNAL_SERVER_ERROR);
ctx.json(BadRequest.internalError(jsonProvider, ex.getMessage()));
}
}
Aggregations