use of tech.pegasys.web3signer.slashingprotection.SlashingProtection in project web3signer by ConsenSys.
the class DeleteKeystoresProcessor method exportSlashingProtectionData.
private String exportSlashingProtectionData(final List<DeleteKeystoreResult> results, final List<String> keysToExport) {
// export slashing protection data for 'deleted' and 'not_active' keys
String slashingProtectionExport = null;
if (slashingProtection.isPresent()) {
try {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final SlashingProtection slashingProtection = this.slashingProtection.get();
try (IncrementalExporter incrementalExporter = slashingProtection.createIncrementalExporter(outputStream)) {
keysToExport.forEach(incrementalExporter::export);
incrementalExporter.finalise();
}
slashingProtectionExport = outputStream.toString(StandardCharsets.UTF_8);
} catch (Exception e) {
LOG.error("Failed to export slashing data", e);
// if export fails - set all results to error
final List<DeleteKeystoreResult> errorResults = results.stream().map(result -> new DeleteKeystoreResult(DeleteKeystoreStatus.ERROR, "Error exporting slashing data: " + e.getMessage())).collect(Collectors.toList());
results.clear();
results.addAll(errorResults);
}
}
return slashingProtectionExport;
}
Aggregations