@Test public void shouldGetValidatorFromState() throws Exception { when(context.pathParamMap()).thenReturn(Map.of("state_id", "head", "validator_id", "1")); when(chainDataProvider.getValidatorDetails(any(), any())) .thenReturn(SafeFuture.completedFuture(Optional.of(validatorResponse))); handler.handle(context); GetStateValidatorResponse response = getResponseFromFuture(GetStateValidatorResponse.class); assertThat(response.data).isEqualTo(validatorResponse); }
@OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get validator from state", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Returns validator specified by state and id or public key along with status and balance.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), @OpenApiParam(name = PARAM_VALIDATOR_ID, description = PARAM_VALIDATOR_DESCRIPTION) }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateValidatorResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override public void handle(@NotNull final Context ctx) throws Exception { final Map<String, String> pathParams = ctx.pathParamMap(); try { final Optional<UInt64> maybeSlot = chainDataProvider.stateParameterToSlot(pathParams.get(PARAM_STATE_ID)); final Optional<Integer> validatorId = chainDataProvider.validatorParameterToIndex(pathParams.get(PARAM_VALIDATOR_ID)); SafeFuture<Optional<ValidatorResponse>> future = chainDataProvider.getValidatorDetails(maybeSlot, validatorId); handleOptionalResult(ctx, future, this::handleResult, SC_NOT_FOUND); } catch (ChainDataUnavailableException ex) { LOG.trace(ex); ctx.status(SC_SERVICE_UNAVAILABLE); } catch (IllegalArgumentException ex) { LOG.trace(ex); ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(ex.getMessage()))); } }
GetStateValidator extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get validator from state", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Returns validator specified by state and id or public key along with status and balance.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), @OpenApiParam(name = PARAM_VALIDATOR_ID, description = PARAM_VALIDATOR_DESCRIPTION) }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateValidatorResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override public void handle(@NotNull final Context ctx) throws Exception { final Map<String, String> pathParams = ctx.pathParamMap(); try { final Optional<UInt64> maybeSlot = chainDataProvider.stateParameterToSlot(pathParams.get(PARAM_STATE_ID)); final Optional<Integer> validatorId = chainDataProvider.validatorParameterToIndex(pathParams.get(PARAM_VALIDATOR_ID)); SafeFuture<Optional<ValidatorResponse>> future = chainDataProvider.getValidatorDetails(maybeSlot, validatorId); handleOptionalResult(ctx, future, this::handleResult, SC_NOT_FOUND); } catch (ChainDataUnavailableException ex) { LOG.trace(ex); ctx.status(SC_SERVICE_UNAVAILABLE); } catch (IllegalArgumentException ex) { LOG.trace(ex); ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(ex.getMessage()))); } } }
GetStateValidator extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get validator from state", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Returns validator specified by state and id or public key along with status and balance.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), @OpenApiParam(name = PARAM_VALIDATOR_ID, description = PARAM_VALIDATOR_DESCRIPTION) }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateValidatorResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override public void handle(@NotNull final Context ctx) throws Exception { final Map<String, String> pathParams = ctx.pathParamMap(); try { final Optional<UInt64> maybeSlot = chainDataProvider.stateParameterToSlot(pathParams.get(PARAM_STATE_ID)); final Optional<Integer> validatorId = chainDataProvider.validatorParameterToIndex(pathParams.get(PARAM_VALIDATOR_ID)); SafeFuture<Optional<ValidatorResponse>> future = chainDataProvider.getValidatorDetails(maybeSlot, validatorId); handleOptionalResult(ctx, future, this::handleResult, SC_NOT_FOUND); } catch (ChainDataUnavailableException ex) { LOG.trace(ex); ctx.status(SC_SERVICE_UNAVAILABLE); } catch (IllegalArgumentException ex) { LOG.trace(ex); ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(ex.getMessage()))); } } GetStateValidator(final DataProvider dataProvider, final JsonProvider jsonProvider);   GetStateValidator(final ChainDataProvider provider, final JsonProvider jsonProvider); }
GetStateValidator extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get validator from state", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Returns validator specified by state and id or public key along with status and balance.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), @OpenApiParam(name = PARAM_VALIDATOR_ID, description = PARAM_VALIDATOR_DESCRIPTION) }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateValidatorResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override public void handle(@NotNull final Context ctx) throws Exception { final Map<String, String> pathParams = ctx.pathParamMap(); try { final Optional<UInt64> maybeSlot = chainDataProvider.stateParameterToSlot(pathParams.get(PARAM_STATE_ID)); final Optional<Integer> validatorId = chainDataProvider.validatorParameterToIndex(pathParams.get(PARAM_VALIDATOR_ID)); SafeFuture<Optional<ValidatorResponse>> future = chainDataProvider.getValidatorDetails(maybeSlot, validatorId); handleOptionalResult(ctx, future, this::handleResult, SC_NOT_FOUND); } catch (ChainDataUnavailableException ex) { LOG.trace(ex); ctx.status(SC_SERVICE_UNAVAILABLE); } catch (IllegalArgumentException ex) { LOG.trace(ex); ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(ex.getMessage()))); } } GetStateValidator(final DataProvider dataProvider, final JsonProvider jsonProvider);   GetStateValidator(final ChainDataProvider provider, final JsonProvider jsonProvider); @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get validator from state", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Returns validator specified by state and id or key along with status and balance.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), @OpenApiParam(name = PARAM_VALIDATOR_ID, description = PARAM_VALIDATOR_DESCRIPTION) }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateValidatorResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override void handle(@NotNull final Context ctx); }
GetStateValidator extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get validator from state", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Returns validator specified by state and id or public key along with status and balance.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), @OpenApiParam(name = PARAM_VALIDATOR_ID, description = PARAM_VALIDATOR_DESCRIPTION) }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateValidatorResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override public void handle(@NotNull final Context ctx) throws Exception { final Map<String, String> pathParams = ctx.pathParamMap(); try { final Optional<UInt64> maybeSlot = chainDataProvider.stateParameterToSlot(pathParams.get(PARAM_STATE_ID)); final Optional<Integer> validatorId = chainDataProvider.validatorParameterToIndex(pathParams.get(PARAM_VALIDATOR_ID)); SafeFuture<Optional<ValidatorResponse>> future = chainDataProvider.getValidatorDetails(maybeSlot, validatorId); handleOptionalResult(ctx, future, this::handleResult, SC_NOT_FOUND); } catch (ChainDataUnavailableException ex) { LOG.trace(ex); ctx.status(SC_SERVICE_UNAVAILABLE); } catch (IllegalArgumentException ex) { LOG.trace(ex); ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(ex.getMessage()))); } } GetStateValidator(final DataProvider dataProvider, final JsonProvider jsonProvider);   GetStateValidator(final ChainDataProvider provider, final JsonProvider jsonProvider); @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get validator from state", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Returns validator specified by state and id or key along with status and balance.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), @OpenApiParam(name = PARAM_VALIDATOR_ID, description = PARAM_VALIDATOR_DESCRIPTION) }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateValidatorResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override void handle(@NotNull final Context ctx); static final String ROUTE; }