@Test void shouldReturnBlockWithGraffiti() throws Exception { final Map<String, List<String>> params = Map.of( RestApiConstants.SLOT, List.of("1"), RANDAO_REVEAL, List.of(signature.toHexString()), RestApiConstants.GRAFFITI, List.of(graffiti.toHexString())); Optional<BeaconBlock> optionalBeaconBlock = Optional.of( new BeaconBlock(dataStructureUtil.randomBeaconBlock(dataStructureUtil.randomLong()))); when(context.queryParamMap()).thenReturn(params); when(provider.getUnsignedBeaconBlockAtSlot(ONE, signature, Optional.of(graffiti))) .thenReturn(SafeFuture.completedFuture(optionalBeaconBlock)); handler.handle(context); verify(context).result(args.capture()); SafeFuture<String> result = args.getValue(); assertThat(result).isCompletedWithValue(jsonProvider.objectToJSON(optionalBeaconBlock.get())); }
@OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Create and return an unsigned beacon block at the specified slot.", tags = {TAG_VALIDATOR}, queryParams = { @OpenApiParam( name = SLOT, description = "`uint64` Slot in which to create the beacon block.", required = true), @OpenApiParam( name = RANDAO_REVEAL, description = "`BLSSignature Hex` BLS12-381 signature for the current epoch.", required = true), @OpenApiParam(name = GRAFFITI, description = "`Bytes32 Hex` Graffiti.") }, description = "Create and return an unsigned beacon block at the specified slot. " + "The `randao_reveal` and `slot` must be provided to create the block.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = BeaconBlock.class), description = "`BeaconBlock` object for the specified slot."), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid parameter supplied") }) @Override public void handle(@NotNull Context ctx) throws Exception { try { final Map<String, List<String>> queryParamMap = ctx.queryParamMap(); BLSSignature randao = getParameterValueAsBLSSignature(queryParamMap, RANDAO_REVEAL); UInt64 slot = getParameterValueAsUInt64(queryParamMap, SLOT); Optional<Bytes32> graffiti = getOptionalParameterValueAsBytes32(queryParamMap, GRAFFITI); ctx.result( provider .getUnsignedBeaconBlockAtSlot(slot, randao, graffiti) .thenApplyChecked( maybeBlock -> { if (maybeBlock.isEmpty()) { throw new ChainDataUnavailableException(); } return jsonProvider.objectToJSON(maybeBlock.get()); }) .exceptionallyCompose(error -> handleError(ctx, error))); } catch (final IllegalArgumentException e) { ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); } }
GetNewBlock implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Create and return an unsigned beacon block at the specified slot.", tags = {TAG_VALIDATOR}, queryParams = { @OpenApiParam( name = SLOT, description = "`uint64` Slot in which to create the beacon block.", required = true), @OpenApiParam( name = RANDAO_REVEAL, description = "`BLSSignature Hex` BLS12-381 signature for the current epoch.", required = true), @OpenApiParam(name = GRAFFITI, description = "`Bytes32 Hex` Graffiti.") }, description = "Create and return an unsigned beacon block at the specified slot. " + "The `randao_reveal` and `slot` must be provided to create the block.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = BeaconBlock.class), description = "`BeaconBlock` object for the specified slot."), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid parameter supplied") }) @Override public void handle(@NotNull Context ctx) throws Exception { try { final Map<String, List<String>> queryParamMap = ctx.queryParamMap(); BLSSignature randao = getParameterValueAsBLSSignature(queryParamMap, RANDAO_REVEAL); UInt64 slot = getParameterValueAsUInt64(queryParamMap, SLOT); Optional<Bytes32> graffiti = getOptionalParameterValueAsBytes32(queryParamMap, GRAFFITI); ctx.result( provider .getUnsignedBeaconBlockAtSlot(slot, randao, graffiti) .thenApplyChecked( maybeBlock -> { if (maybeBlock.isEmpty()) { throw new ChainDataUnavailableException(); } return jsonProvider.objectToJSON(maybeBlock.get()); }) .exceptionallyCompose(error -> handleError(ctx, error))); } catch (final IllegalArgumentException e) { ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); } } }
GetNewBlock implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Create and return an unsigned beacon block at the specified slot.", tags = {TAG_VALIDATOR}, queryParams = { @OpenApiParam( name = SLOT, description = "`uint64` Slot in which to create the beacon block.", required = true), @OpenApiParam( name = RANDAO_REVEAL, description = "`BLSSignature Hex` BLS12-381 signature for the current epoch.", required = true), @OpenApiParam(name = GRAFFITI, description = "`Bytes32 Hex` Graffiti.") }, description = "Create and return an unsigned beacon block at the specified slot. " + "The `randao_reveal` and `slot` must be provided to create the block.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = BeaconBlock.class), description = "`BeaconBlock` object for the specified slot."), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid parameter supplied") }) @Override public void handle(@NotNull Context ctx) throws Exception { try { final Map<String, List<String>> queryParamMap = ctx.queryParamMap(); BLSSignature randao = getParameterValueAsBLSSignature(queryParamMap, RANDAO_REVEAL); UInt64 slot = getParameterValueAsUInt64(queryParamMap, SLOT); Optional<Bytes32> graffiti = getOptionalParameterValueAsBytes32(queryParamMap, GRAFFITI); ctx.result( provider .getUnsignedBeaconBlockAtSlot(slot, randao, graffiti) .thenApplyChecked( maybeBlock -> { if (maybeBlock.isEmpty()) { throw new ChainDataUnavailableException(); } return jsonProvider.objectToJSON(maybeBlock.get()); }) .exceptionallyCompose(error -> handleError(ctx, error))); } catch (final IllegalArgumentException e) { ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); } } GetNewBlock(final DataProvider dataProvider, final JsonProvider jsonProvider);   GetNewBlock(final ValidatorDataProvider provider, final JsonProvider jsonProvider); }
GetNewBlock implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Create and return an unsigned beacon block at the specified slot.", tags = {TAG_VALIDATOR}, queryParams = { @OpenApiParam( name = SLOT, description = "`uint64` Slot in which to create the beacon block.", required = true), @OpenApiParam( name = RANDAO_REVEAL, description = "`BLSSignature Hex` BLS12-381 signature for the current epoch.", required = true), @OpenApiParam(name = GRAFFITI, description = "`Bytes32 Hex` Graffiti.") }, description = "Create and return an unsigned beacon block at the specified slot. " + "The `randao_reveal` and `slot` must be provided to create the block.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = BeaconBlock.class), description = "`BeaconBlock` object for the specified slot."), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid parameter supplied") }) @Override public void handle(@NotNull Context ctx) throws Exception { try { final Map<String, List<String>> queryParamMap = ctx.queryParamMap(); BLSSignature randao = getParameterValueAsBLSSignature(queryParamMap, RANDAO_REVEAL); UInt64 slot = getParameterValueAsUInt64(queryParamMap, SLOT); Optional<Bytes32> graffiti = getOptionalParameterValueAsBytes32(queryParamMap, GRAFFITI); ctx.result( provider .getUnsignedBeaconBlockAtSlot(slot, randao, graffiti) .thenApplyChecked( maybeBlock -> { if (maybeBlock.isEmpty()) { throw new ChainDataUnavailableException(); } return jsonProvider.objectToJSON(maybeBlock.get()); }) .exceptionallyCompose(error -> handleError(ctx, error))); } catch (final IllegalArgumentException e) { ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); } } GetNewBlock(final DataProvider dataProvider, final JsonProvider jsonProvider);   GetNewBlock(final ValidatorDataProvider provider, final JsonProvider jsonProvider); @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Create and return an unsigned beacon block at the specified slot.", tags = {TAG_VALIDATOR}, queryParams = { @OpenApiParam( name = SLOT, description = "`uint64` Slot in which to create the beacon block.", required = true), @OpenApiParam( name = RANDAO_REVEAL, description = "`BLSSignature Hex` BLS12-381 signature for the current epoch.", required = true), @OpenApiParam(name = GRAFFITI, description = "`Bytes32 Hex` Graffiti.") }, description = "Create and return an unsigned beacon block at the specified slot. " + "The `randao_reveal` and `slot` must be provided to create the block.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = BeaconBlock.class), description = "`BeaconBlock` object for the specified slot."), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid parameter supplied") }) @Override void handle(@NotNull Context ctx); }
GetNewBlock implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Create and return an unsigned beacon block at the specified slot.", tags = {TAG_VALIDATOR}, queryParams = { @OpenApiParam( name = SLOT, description = "`uint64` Slot in which to create the beacon block.", required = true), @OpenApiParam( name = RANDAO_REVEAL, description = "`BLSSignature Hex` BLS12-381 signature for the current epoch.", required = true), @OpenApiParam(name = GRAFFITI, description = "`Bytes32 Hex` Graffiti.") }, description = "Create and return an unsigned beacon block at the specified slot. " + "The `randao_reveal` and `slot` must be provided to create the block.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = BeaconBlock.class), description = "`BeaconBlock` object for the specified slot."), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid parameter supplied") }) @Override public void handle(@NotNull Context ctx) throws Exception { try { final Map<String, List<String>> queryParamMap = ctx.queryParamMap(); BLSSignature randao = getParameterValueAsBLSSignature(queryParamMap, RANDAO_REVEAL); UInt64 slot = getParameterValueAsUInt64(queryParamMap, SLOT); Optional<Bytes32> graffiti = getOptionalParameterValueAsBytes32(queryParamMap, GRAFFITI); ctx.result( provider .getUnsignedBeaconBlockAtSlot(slot, randao, graffiti) .thenApplyChecked( maybeBlock -> { if (maybeBlock.isEmpty()) { throw new ChainDataUnavailableException(); } return jsonProvider.objectToJSON(maybeBlock.get()); }) .exceptionallyCompose(error -> handleError(ctx, error))); } catch (final IllegalArgumentException e) { ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(e.getMessage()))); } } GetNewBlock(final DataProvider dataProvider, final JsonProvider jsonProvider);   GetNewBlock(final ValidatorDataProvider provider, final JsonProvider jsonProvider); @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Create and return an unsigned beacon block at the specified slot.", tags = {TAG_VALIDATOR}, queryParams = { @OpenApiParam( name = SLOT, description = "`uint64` Slot in which to create the beacon block.", required = true), @OpenApiParam( name = RANDAO_REVEAL, description = "`BLSSignature Hex` BLS12-381 signature for the current epoch.", required = true), @OpenApiParam(name = GRAFFITI, description = "`Bytes32 Hex` Graffiti.") }, description = "Create and return an unsigned beacon block at the specified slot. " + "The `randao_reveal` and `slot` must be provided to create the block.", responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = BeaconBlock.class), description = "`BeaconBlock` object for the specified slot."), @OpenApiResponse(status = RES_NO_CONTENT, description = NO_CONTENT_PRE_GENESIS), @OpenApiResponse(status = RES_BAD_REQUEST, description = "Invalid parameter supplied") }) @Override void handle(@NotNull Context ctx); static final String ROUTE; }