use of tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2 in project teku by ConsenSys.
the class GetStateIntegrationTest method shouldGetAltairStateAsJson.
@Test
public void shouldGetAltairStateAsJson() throws IOException {
startRestAPIAtGenesis(SpecMilestone.ALTAIR);
final Response response = get("head", HEADER_ACCEPT_JSON);
assertThat(response.code()).isEqualTo(SC_OK);
final GetStateResponseV2 stateResponse = jsonProvider.jsonToObject(response.body().string(), GetStateResponseV2.class);
assertThat(stateResponse).isNotNull();
assertThat(stateResponse.version).isEqualTo(Version.altair);
assertThat(stateResponse.data).isInstanceOf(BeaconStateAltair.class);
assertThat(response.header(HEADER_CONSENSUS_VERSION)).isEqualTo(Version.altair.name());
}
use of tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2 in project teku by ConsenSys.
the class GetStateResponseV2Deserializer method deserialize.
@Override
public GetStateResponseV2 deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
JsonNode node = jp.getCodec().readTree(jp);
final Version version = Version.valueOf(node.findValue("version").asText().toLowerCase(Locale.ROOT));
final JsonNode executionOptimisticNode = node.findValue("execution_optimistic");
final Boolean executionOptimistic = executionOptimisticNode != null ? executionOptimisticNode.asBoolean() : null;
final BeaconState state;
switch(version) {
case altair:
state = mapper.treeToValue(node.findValue("data"), BeaconStateAltair.class);
break;
case phase0:
state = mapper.treeToValue(node.findValue("data"), BeaconStatePhase0.class);
break;
default:
throw new IOException("Milestone was not able to be decoded");
}
return new GetStateResponseV2(version, executionOptimistic, state);
}
use of tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2 in project teku by ConsenSys.
the class GetState method handleJsonResult.
private Optional<String> handleJsonResult(Context ctx, final ObjectAndMetaData<BeaconState> response) throws JsonProcessingException {
final Version version = Version.fromMilestone(response.getMilestone());
ctx.header(HEADER_CONSENSUS_VERSION, version.name());
return Optional.of(jsonProvider.objectToJSON(new GetStateResponseV2(version, response.isExecutionOptimisticForApi(), response.getData())));
}
use of tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2 in project teku by ConsenSys.
the class GetStateIntegrationTest method shouldGetPhase0StateAsJson.
@Test
public void shouldGetPhase0StateAsJson() throws IOException {
startRestAPIAtGenesis(SpecMilestone.PHASE0);
final Response response = get("head", HEADER_ACCEPT_JSON);
assertThat(response.code()).isEqualTo(SC_OK);
final GetStateResponseV2 stateResponse = jsonProvider.jsonToObject(response.body().string(), GetStateResponseV2.class);
assertThat(stateResponse).isNotNull();
assertThat(stateResponse.version).isEqualTo(Version.phase0);
assertThat(stateResponse.data).isInstanceOf(BeaconStatePhase0.class);
assertThat(response.header(HEADER_CONSENSUS_VERSION)).isEqualTo(Version.phase0.name());
}
Aggregations