Search in sources :

Example 1 with GenesisValidatorRootValidator

use of tech.pegasys.web3signer.slashingprotection.validator.GenesisValidatorRootValidator in project web3signer by ConsenSys.

the class InterchangeV5Importer method importDataInternal.

private void importDataInternal(final InputStream input, final Optional<List<String>> pubkeys) throws IOException {
    try (final JsonParser jsonParser = JSON_MAPPER.getFactory().createParser(input)) {
        final ObjectNode rootNode = JSON_MAPPER.readTree(jsonParser);
        final JsonNode metadataJsonNode = rootNode.get("metadata");
        final Metadata metadata = JSON_MAPPER.treeToValue(metadataJsonNode, Metadata.class);
        if (!metadata.getFormatVersion().equals(FORMAT_VERSION)) {
            throw new IllegalStateException("Expecting an interchange_format_version of " + FORMAT_VERSION);
        }
        final Bytes32 gvr = Bytes32.wrap(metadata.getGenesisValidatorsRoot());
        final GenesisValidatorRootValidator genesisValidatorRootValidator = new GenesisValidatorRootValidator(jdbi, metadataDao);
        if (!genesisValidatorRootValidator.checkGenesisValidatorsRootAndInsertIfEmpty(gvr)) {
            throw new IllegalArgumentException(String.format("Supplied genesis validators root %s does not match value in database", gvr));
        }
        final ArrayNode dataNode = rootNode.withArray("data");
        jdbi.useTransaction(h -> {
            for (int i = 0; i < dataNode.size(); i++) {
                try {
                    final JsonNode validatorNode = dataNode.get(i);
                    parseValidator(h, validatorNode, pubkeys);
                } catch (final IllegalArgumentException e) {
                    LOG.error("Failed to parse validator {}, due to {}", i, e.getMessage());
                    throw e;
                }
            }
        });
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GenesisValidatorRootValidator(tech.pegasys.web3signer.slashingprotection.validator.GenesisValidatorRootValidator) Metadata(tech.pegasys.web3signer.slashingprotection.interchange.model.Metadata) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Bytes32(org.apache.tuweni.bytes.Bytes32) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 Metadata (tech.pegasys.web3signer.slashingprotection.interchange.model.Metadata)1 GenesisValidatorRootValidator (tech.pegasys.web3signer.slashingprotection.validator.GenesisValidatorRootValidator)1