Search in sources :

Example 1 with Version

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);
}
Also used : GetStateResponseV2(tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2) Version(tech.pegasys.teku.api.schema.Version) JsonNode(com.fasterxml.jackson.databind.JsonNode) BeaconStatePhase0(tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0) IOException(java.io.IOException) BeaconStateAltair(tech.pegasys.teku.api.schema.altair.BeaconStateAltair) BeaconState(tech.pegasys.teku.api.schema.BeaconState)

Example 2 with Version

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);
}
Also used : GetNewBlockResponseV2(tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2) BeaconBlockPhase0(tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0) Version(tech.pegasys.teku.api.schema.Version) BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) BeaconBlockBellatrix(tech.pegasys.teku.api.schema.bellatrix.BeaconBlockBellatrix) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) BeaconBlockAltair(tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)

Example 3 with Version

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())));
}
Also used : GetStateResponseV2(tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2) Version(tech.pegasys.teku.api.schema.Version)

Example 4 with Version

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())));
}
Also used : Version(tech.pegasys.teku.api.schema.Version) GetBlockResponseV2(tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2)

Aggregations

Version (tech.pegasys.teku.api.schema.Version)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 IOException (java.io.IOException)2 GetStateResponseV2 (tech.pegasys.teku.api.response.v2.debug.GetStateResponseV2)2 GetBlockResponseV2 (tech.pegasys.teku.api.response.v2.beacon.GetBlockResponseV2)1 GetNewBlockResponseV2 (tech.pegasys.teku.api.response.v2.validator.GetNewBlockResponseV2)1 BeaconBlock (tech.pegasys.teku.api.schema.BeaconBlock)1 BeaconState (tech.pegasys.teku.api.schema.BeaconState)1 BeaconBlockAltair (tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)1 BeaconStateAltair (tech.pegasys.teku.api.schema.altair.BeaconStateAltair)1 BeaconBlockBellatrix (tech.pegasys.teku.api.schema.bellatrix.BeaconBlockBellatrix)1 BeaconBlockPhase0 (tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0)1 BeaconStatePhase0 (tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0)1