use of tech.pegasys.teku.data.SlashingProtectionImporter in project teku by ConsenSys.
the class ImportCommand method run.
@Override
public void run() {
final Path slashProtectionPath = SlashingProtectionCommandUtils.getSlashingProtectionPath(dataOptions);
File importFile = new File(fromFileName);
verifyImportFileExists(importFile);
prepareOutputPath(slashProtectionPath.toFile());
SlashingProtectionImporter importer = new SlashingProtectionImporter(slashProtectionPath);
try {
SUB_COMMAND_LOG.display("Reading slashing protection data from: " + importFile);
final Optional<String> errorCondition = importer.initialise(importFile);
errorCondition.ifPresent(s -> SUB_COMMAND_LOG.exit(1, s));
} catch (IOException e) {
String cause = e.getCause() != null ? e.getCause().getMessage() : e.getMessage();
SUB_COMMAND_LOG.exit(1, String.format("Failed to read from import file: %s. %s" + importFile, cause));
}
SUB_COMMAND_LOG.display("Writing slashing protection data to: " + slashProtectionPath);
importer.updateLocalRecords(SUB_COMMAND_LOG::display);
}
use of tech.pegasys.teku.data.SlashingProtectionImporter in project teku by ConsenSys.
the class PostKeys method readSlashingProtectionDataIfPresent.
private Optional<SlashingProtectionImporter> readSlashingProtectionDataIfPresent(final Optional<String> slashingData) {
if (slashingData.isPresent()) {
final InputStream slashingProtectionData = IOUtils.toInputStream(slashingData.get(), StandardCharsets.UTF_8);
final SlashingProtectionImporter importer = new SlashingProtectionImporter(slashingProtectionPath);
try {
final Optional<String> initialiseError = importer.initialise(slashingProtectionData);
if (initialiseError.isPresent()) {
throw new BadRequestException(initialiseError.get());
}
return Optional.of(importer);
} catch (IOException ex) {
throw new BadRequestException(ex.getMessage());
}
}
return Optional.empty();
}
use of tech.pegasys.teku.data.SlashingProtectionImporter in project teku by ConsenSys.
the class PostKeys method handle.
@Override
public void handle(final RestApiRequest request) throws JsonProcessingException {
final PostKeysRequest body = request.getRequestBody();
if (body.getPasswords().size() != body.getKeystores().size()) {
request.respondError(SC_BAD_REQUEST, String.format("Keystores count (%d) and Passwords count (%d) differ, cannot proceed.", body.getKeystores().size(), body.getPasswords().size()));
return;
}
if (body.getKeystores().isEmpty()) {
request.respondOk(Collections.emptyList());
return;
}
final Optional<SlashingProtectionImporter> slashingData = readSlashingProtectionDataIfPresent(body.getSlashingProtection());
request.respondOk(keyManager.importValidators(body.getKeystores(), body.getPasswords(), slashingData));
}
Aggregations