use of tech.pegasys.teku.infrastructure.http.RestApiConstants.PARENT_ROOT 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())));
}
}
Aggregations