Search in sources :

Example 1 with BeaconBlockHeader

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;
}
Also used : BeaconBlock(tech.pegasys.teku.api.schema.BeaconBlock) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) BeaconBlockHeader(tech.pegasys.teku.api.schema.BeaconBlockHeader) BlockRequest(tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest) SpecMilestone(tech.pegasys.teku.spec.SpecMilestone) BeaconBlockAltair(tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)

Example 2 with BeaconBlockHeader

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()));
}
Also used : SignedBeaconBlockHeader(tech.pegasys.teku.api.schema.SignedBeaconBlockHeader) SignedBeaconBlockHeader(tech.pegasys.teku.api.schema.SignedBeaconBlockHeader) BlockHeader(tech.pegasys.teku.api.response.v1.beacon.BlockHeader) BeaconBlockHeader(tech.pegasys.teku.api.schema.BeaconBlockHeader) SignedBeaconBlockHeader(tech.pegasys.teku.api.schema.SignedBeaconBlockHeader) BeaconBlockHeader(tech.pegasys.teku.api.schema.BeaconBlockHeader) BLSSignature(tech.pegasys.teku.api.schema.BLSSignature) Test(org.junit.jupiter.api.Test)

Aggregations

BeaconBlockHeader (tech.pegasys.teku.api.schema.BeaconBlockHeader)2 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Test (org.junit.jupiter.api.Test)1 BlockHeader (tech.pegasys.teku.api.response.v1.beacon.BlockHeader)1 BLSSignature (tech.pegasys.teku.api.schema.BLSSignature)1 BeaconBlock (tech.pegasys.teku.api.schema.BeaconBlock)1 SignedBeaconBlockHeader (tech.pegasys.teku.api.schema.SignedBeaconBlockHeader)1 BeaconBlockAltair (tech.pegasys.teku.api.schema.altair.BeaconBlockAltair)1 SpecMilestone (tech.pegasys.teku.spec.SpecMilestone)1 BlockRequest (tech.pegasys.web3signer.core.service.http.handlers.signing.eth2.BlockRequest)1