use of tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_BEACON in project teku by ConsenSys.
the class GetBlockHeaders method handle.
@OpenApi(path = ROUTE, method = HttpMethod.GET, summary = "Get block headers", tags = { TAG_BEACON }, description = "Retrieves block headers matching given query. By default it will fetch current head slot blocks.", queryParams = { @OpenApiParam(name = SLOT), @OpenApiParam(name = PARENT_ROOT, description = "Not currently supported.") }, responses = { @OpenApiResponse(status = RES_OK, content = @OpenApiContent(from = GetBlockHeadersResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_INTERNAL_ERROR) })
@Override
public void handle(@NotNull final Context ctx) throws Exception {
final Map<String, List<String>> queryParameters = ctx.queryParamMap();
final Optional<Bytes32> parentRoot = SingleQueryParameterUtils.getParameterValueAsBytes32IfPresent(queryParameters, PARENT_ROOT);
final Optional<UInt64> slot = SingleQueryParameterUtils.getParameterValueAsUInt64IfPresent(queryParameters, SLOT);
try {
ctx.future(chainDataProvider.getBlockHeaders(parentRoot, slot).thenApplyChecked(jsonProvider::objectToJSON).exceptionallyCompose(error -> handleError(ctx, error)));
} catch (final IllegalArgumentException e) {
ctx.status(SC_BAD_REQUEST);
ctx.json(jsonProvider.objectToJSON(new BadRequest(e.getMessage())));
}
}
use of tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_BEACON 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()));
}
}
use of tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_BEACON in project teku by ConsenSys.
the class PostVoluntaryExit method handle.
@OpenApi(path = ROUTE, method = HttpMethod.POST, summary = "Submit signed voluntary exit", tags = { TAG_BEACON }, description = "Submits signed voluntary exit object to node's pool and if it passes validation node MUST broadcast it to network.", requestBody = @OpenApiRequestBody(content = { @OpenApiContent(from = SignedVoluntaryExit.class) }), responses = { @OpenApiResponse(status = RES_OK, description = "Signed voluntary exit has been successfully validated, added to the pool, and broadcast."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid voluntary exit, it will never pass validation so it's rejected"), @OpenApiResponse(status = RES_INTERNAL_ERROR) })
@Override
public void handle(final Context ctx) throws Exception {
try {
final SignedVoluntaryExit exit = parseRequestBody(ctx.body(), SignedVoluntaryExit.class);
ctx.future(nodeDataProvider.postVoluntaryExit(exit).thenApplyChecked(result -> handleResponseContext(ctx, result)));
} catch (final IllegalArgumentException e) {
LOG.debug("Voluntary exit failed", e);
ctx.json(BadRequest.badRequest(jsonProvider, e.getMessage()));
ctx.status(SC_BAD_REQUEST);
}
}
Aggregations