use of tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0 in project teku by ConsenSys.
the class GetBlockV2IntegrationTest method shouldGetBlock.
@Test
public void shouldGetBlock() throws IOException {
startRestAPIAtGenesis(SpecMilestone.PHASE0);
final List<SignedBlockAndState> created = createBlocksAtSlots(10);
final Response response = get("head");
final GetBlockResponseV2 body = jsonProvider.jsonToObject(response.body().string(), GetBlockResponseV2.class);
assertThat(body.getVersion()).isEqualTo(Version.phase0);
assertThat(body.data).isInstanceOf(SignedBeaconBlockPhase0.class);
final SignedBeaconBlockPhase0 data = (SignedBeaconBlockPhase0) body.getData();
final SignedBlockAndState block = created.get(0);
assertThat(data).isEqualTo(SignedBeaconBlock.create(block.getBlock()));
assertThat(response.header(HEADER_CONSENSUS_VERSION)).isEqualTo(Version.phase0.name());
}
use of tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0 in project teku by ConsenSys.
the class ValidatorDataProvider method parseBlock.
public SignedBeaconBlock parseBlock(final JsonProvider jsonProvider, final String jsonBlock) throws JsonProcessingException {
final ObjectMapper mapper = jsonProvider.getObjectMapper();
final JsonNode jsonNode = mapper.readTree(jsonBlock);
final UInt64 slot = mapper.treeToValue(jsonNode.findValue("slot"), UInt64.class);
final SignedBeaconBlock signedBeaconBlock;
checkNotNull(slot, "Slot was not found in json block");
switch(spec.atSlot(slot).getMilestone()) {
case PHASE0:
signedBeaconBlock = mapper.treeToValue(jsonNode, SignedBeaconBlockPhase0.class);
break;
case ALTAIR:
signedBeaconBlock = mapper.treeToValue(jsonNode, SignedBeaconBlockAltair.class);
break;
case BELLATRIX:
signedBeaconBlock = mapper.treeToValue(jsonNode, SignedBeaconBlockBellatrix.class);
break;
default:
throw new IllegalArgumentException("Could not determine milestone for slot " + slot);
}
return signedBeaconBlock;
}
Aggregations