use of tech.pegasys.teku.beaconrestapi.schema.BadRequest in project teku by ConsenSys.
the class GetStateCommitteesTest method shouldGetBadRequestIfEpochTooFarInFuture.
@Test
public void shouldGetBadRequestIfEpochTooFarInFuture() throws IOException {
final Response response = get("head", Map.of("epoch", "1024000"));
assertThat(response.code()).isEqualTo(SC_BAD_REQUEST);
final BadRequest body = jsonProvider.jsonToObject(response.body().string(), BadRequest.class);
assertThat(body.getCode()).isEqualTo(SC_BAD_REQUEST);
assertThat(body.getMessage()).startsWith("Epoch 1024000 is too far ahead ");
}
use of tech.pegasys.teku.beaconrestapi.schema.BadRequest 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.beaconrestapi.schema.BadRequest in project teku by ConsenSys.
the class PutLogLevel method handle.
@OpenApi(path = ROUTE, method = HttpMethod.PUT, summary = "Changes the log level without restarting.", tags = { TAG_TEKU }, requestBody = @OpenApiRequestBody(content = { @OpenApiContent(from = LogLevel.class) }, description = "```\n{\n \"level\": (String; acceptable values: ALL, TRACE, DEBUG, INFO, ERROR, FATAL, OFF ),\n" + " \"log_filter\": [(String; Optional)]\n}\n```"), description = "Changes the log level without restarting. You can change the log level for all logs, or the log level for specific packages or classes.", responses = { @OpenApiResponse(status = RES_NO_CONTENT, description = "The LogLevel was accepted and applied"), @OpenApiResponse(status = RES_BAD_REQUEST, description = INVALID_BODY_SUPPLIED), @OpenApiResponse(status = RES_INTERNAL_ERROR) })
@Override
public void handle(final Context ctx) throws Exception {
try {
final LogLevel params = parseRequestBody(ctx.body(), LogLevel.class);
final String[] logFilters = params.getLogFilter().orElseGet(() -> new String[] { "" });
for (final String logFilter : logFilters) {
LoggingConfigurator.setAllLevels(logFilter, params.getLevel());
}
ctx.status(SC_NO_CONTENT);
} catch (final IllegalArgumentException e) {
ctx.json(jsonProvider.objectToJSON(new BadRequest(e.getMessage())));
ctx.status(SC_BAD_REQUEST);
}
}
use of tech.pegasys.teku.beaconrestapi.schema.BadRequest in project teku by ConsenSys.
the class GetAttestationDataTest method badRequestParamsTest.
private void badRequestParamsTest(final Map<String, List<String>> params, String message) throws Exception {
when(context.queryParamMap()).thenReturn(params);
handler.handle(context);
verify(context).status(SC_BAD_REQUEST);
if (StringUtils.isNotEmpty(message)) {
BadRequest badRequest = new BadRequest(message);
verify(context).json(jsonProvider.objectToJSON(badRequest));
}
}
use of tech.pegasys.teku.beaconrestapi.schema.BadRequest in project teku by ConsenSys.
the class GetAggregateAttestation method handle.
@OpenApi(path = ROUTE, method = HttpMethod.GET, summary = "Get aggregated attestations", description = "Aggregates all attestations matching given attestation data root and slot.", tags = { TAG_VALIDATOR, TAG_VALIDATOR_REQUIRED }, queryParams = { @OpenApiParam(name = ATTESTATION_DATA_ROOT, description = "`String` HashTreeRoot of AttestationData that validator wants aggregated.", required = true), @OpenApiParam(name = SLOT, description = "`uint64` Non-finalized slot for which to create the aggregation.", required = true) }, responses = { @OpenApiResponse(status = RES_OK, content = @OpenApiContent(from = GetAggregatedAttestationResponse.class), description = "Returns aggregated `Attestation` object with same `AttestationData` root."), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid parameter supplied"), @OpenApiResponse(status = RES_NOT_FOUND, description = "No matching attestations were found"), @OpenApiResponse(status = RES_FORBIDDEN, description = "Beacon node was not assigned to aggregate on that subnet"), @OpenApiResponse(status = RES_INTERNAL_ERROR, description = "Beacon node internal error.") })
@Override
public void handle(Context ctx) throws Exception {
try {
final Map<String, List<String>> parameters = ctx.queryParamMap();
if (parameters.size() < 2) {
throw new IllegalArgumentException(String.format("Please specify both %s and %s", ATTESTATION_DATA_ROOT, SLOT));
}
Bytes32 beacon_block_root = getParameterValueAsBytes32(parameters, ATTESTATION_DATA_ROOT);
final UInt64 slot = getParameterValueAsUInt64(parameters, SLOT);
ctx.future(provider.createAggregate(slot, beacon_block_root).thenApplyChecked(optionalAttestation -> serializeResult(ctx, optionalAttestation)).exceptionallyCompose(error -> handleError(ctx, error)));
} catch (final IllegalArgumentException e) {
ctx.json(jsonProvider.objectToJSON(new BadRequest(e.getMessage())));
ctx.status(SC_BAD_REQUEST);
}
}
Aggregations