use of tech.pegasys.teku.api.schema.BeaconBlockHeader in project web3signer by ConsenSys.
the class BlockRequestDeserializer method deserialize.
@Override
public BlockRequest deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
final ObjectCodec codec = p.getCodec();
final JsonNode node = codec.readTree(p);
final SpecMilestone specMilestone = SpecMilestone.valueOf(node.findValue("version").asText());
final BeaconBlock beaconBlock;
final BeaconBlockHeader beaconBlockHeader;
final BlockRequest blockRequest;
switch(specMilestone) {
case PHASE0:
beaconBlock = codec.treeToValue(node.findValue("block"), BeaconBlock.class);
blockRequest = new BlockRequest(specMilestone, beaconBlock);
break;
case ALTAIR:
beaconBlock = codec.treeToValue(node.findValue("block"), BeaconBlockAltair.class);
blockRequest = new BlockRequest(specMilestone, beaconBlock);
break;
case BELLATRIX:
// for BELLATRIX we only need block_header instead of complete block
beaconBlockHeader = codec.treeToValue(node.findValue("block_header"), BeaconBlockHeader.class);
blockRequest = new BlockRequest(specMilestone, beaconBlockHeader);
break;
default:
throw new IllegalStateException("Fork version not yet supported: " + specMilestone);
}
return blockRequest;
}
use of tech.pegasys.teku.api.schema.BeaconBlockHeader in project teku by ConsenSys.
the class ChainDataProviderTest method getBlockHeaderByBlockId_shouldGetHeadBlock.
@Test
public void getBlockHeaderByBlockId_shouldGetHeadBlock() throws ExecutionException, InterruptedException {
final ChainDataProvider provider = new ChainDataProvider(spec, recentChainData, combinedChainDataClient);
final tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock block = storageSystem.getChainHead().getSignedBeaconBlock().orElseThrow();
ObjectAndMetaData<BlockHeader> result = provider.getBlockHeader("head").get().orElseThrow();
final BeaconBlockHeader beaconBlockHeader = new BeaconBlockHeader(block.getSlot(), block.getMessage().getProposerIndex(), block.getParentRoot(), block.getStateRoot(), block.getBodyRoot());
final BlockHeader expected = new BlockHeader(block.getRoot(), true, new SignedBeaconBlockHeader(beaconBlockHeader, new BLSSignature(block.getSignature())));
assertThat(result).isEqualTo(addMetaData(expected, block.getSlot()));
}
Aggregations