Search in sources :

Example 1 with PARENT_ROOT

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())));
    }
}
Also used : AbstractHandler(tech.pegasys.teku.beaconrestapi.handlers.AbstractHandler) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) TAG_BEACON(tech.pegasys.teku.infrastructure.http.RestApiConstants.TAG_BEACON) OpenApiContent(io.javalin.plugin.openapi.annotations.OpenApiContent) SLOT(tech.pegasys.teku.infrastructure.http.RestApiConstants.SLOT) RES_INTERNAL_ERROR(tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_INTERNAL_ERROR) RES_BAD_REQUEST(tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_BAD_REQUEST) PARENT_ROOT(tech.pegasys.teku.infrastructure.http.RestApiConstants.PARENT_ROOT) Context(io.javalin.http.Context) OpenApiResponse(io.javalin.plugin.openapi.annotations.OpenApiResponse) Map(java.util.Map) JsonProvider(tech.pegasys.teku.provider.JsonProvider) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) ChainDataProvider(tech.pegasys.teku.api.ChainDataProvider) HttpMethod(io.javalin.plugin.openapi.annotations.HttpMethod) BadRequest(tech.pegasys.teku.beaconrestapi.schema.BadRequest) Throwables(com.google.common.base.Throwables) SingleQueryParameterUtils(tech.pegasys.teku.beaconrestapi.SingleQueryParameterUtils) Handler(io.javalin.http.Handler) List(java.util.List) OpenApiParam(io.javalin.plugin.openapi.annotations.OpenApiParam) RES_OK(tech.pegasys.teku.infrastructure.http.RestApiConstants.RES_OK) Optional(java.util.Optional) SC_BAD_REQUEST(javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST) GetBlockHeadersResponse(tech.pegasys.teku.api.response.v1.beacon.GetBlockHeadersResponse) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi) NotNull(org.jetbrains.annotations.NotNull) DataProvider(tech.pegasys.teku.api.DataProvider) BadRequest(tech.pegasys.teku.beaconrestapi.schema.BadRequest) List(java.util.List) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi)

Aggregations

Throwables (com.google.common.base.Throwables)1 Context (io.javalin.http.Context)1 Handler (io.javalin.http.Handler)1 HttpMethod (io.javalin.plugin.openapi.annotations.HttpMethod)1 OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)1 OpenApiContent (io.javalin.plugin.openapi.annotations.OpenApiContent)1 OpenApiParam (io.javalin.plugin.openapi.annotations.OpenApiParam)1 OpenApiResponse (io.javalin.plugin.openapi.annotations.OpenApiResponse)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 SC_BAD_REQUEST (javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 NotNull (org.jetbrains.annotations.NotNull)1 ChainDataProvider (tech.pegasys.teku.api.ChainDataProvider)1 DataProvider (tech.pegasys.teku.api.DataProvider)1 GetBlockHeadersResponse (tech.pegasys.teku.api.response.v1.beacon.GetBlockHeadersResponse)1 SingleQueryParameterUtils (tech.pegasys.teku.beaconrestapi.SingleQueryParameterUtils)1 AbstractHandler (tech.pegasys.teku.beaconrestapi.handlers.AbstractHandler)1 BadRequest (tech.pegasys.teku.beaconrestapi.schema.BadRequest)1