Search in sources :

Example 1 with SlashingProtection

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;
}
Also used : IncrementalExporter(tech.pegasys.web3signer.slashingprotection.interchange.IncrementalExporter) ArrayList(java.util.ArrayList) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SlashingProtection(tech.pegasys.web3signer.slashingprotection.SlashingProtection)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SlashingProtection (tech.pegasys.web3signer.slashingprotection.SlashingProtection)1 IncrementalExporter (tech.pegasys.web3signer.slashingprotection.interchange.IncrementalExporter)1