use of tech.pegasys.teku.api.schema.Version 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.schema.Version in project teku by ConsenSys.
the class GetNewBlockResponseV2Deserializer method deserialize.
@Override
public GetNewBlockResponseV2 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 BeaconBlock block;
switch(version) {
case bellatrix:
block = mapper.treeToValue(node.findValue("data"), BeaconBlockBellatrix.class);
break;
case altair:
block = mapper.treeToValue(node.findValue("data"), BeaconBlockAltair.class);
break;
case phase0:
block = mapper.treeToValue(node.findValue("data"), BeaconBlockPhase0.class);
break;
default:
throw new IOException("Milestone was not able to be decoded");
}
return new GetNewBlockResponseV2(version, block);
}
use of tech.pegasys.teku.api.schema.Version 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.schema.Version in project teku by ConsenSys.
the class GetBlock method handleJsonResult.
private Optional<String> handleJsonResult(Context ctx, final ObjectAndMetaData<SignedBeaconBlock> response) throws JsonProcessingException {
final Version version = Version.fromMilestone(response.getMilestone());
ctx.header(HEADER_CONSENSUS_VERSION, version.name());
return Optional.of(jsonProvider.objectToJSON(new GetBlockResponseV2(version, response.isExecutionOptimisticForApi(), response.getData())));
}
Aggregations