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;
}
}
});
}
}
Aggregations