Search in sources :

Example 1 with DeleteRemoteKeysResponse

use of tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteRemoteKeysResponse in project teku by ConsenSys.

the class ActiveKeyManager method deleteExternalValidators.

@Override
public DeleteRemoteKeysResponse deleteExternalValidators(List<BLSPublicKey> validators) {
    final List<DeleteKeyResult> deletionResults = new ArrayList<>();
    for (final BLSPublicKey publicKey : validators) {
        Optional<Validator> maybeValidator = validatorLoader.getOwnedValidators().getValidator(publicKey);
        // read-only check in a non-destructive manner
        if (maybeValidator.isPresent() && maybeValidator.get().isReadOnly()) {
            deletionResults.add(DeleteKeyResult.error("Cannot remove read-only validator"));
            continue;
        }
        // delete validator from owned validators list
        maybeValidator = validatorLoader.getOwnedValidators().getValidator(publicKey);
        if (maybeValidator.isPresent()) {
            DeleteKeyResult result = deleteExternalValidator(maybeValidator.get());
            deletionResults.add(result);
            if (result.equals(DeleteKeyResult.success())) {
                validatorLoader.getOwnedValidators().removeValidator(publicKey);
            }
        } else {
            deletionResults.add(DeleteKeyResult.notFound());
        }
    }
    return new DeleteRemoteKeysResponse(deletionResults);
}
Also used : DeleteRemoteKeysResponse(tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteRemoteKeysResponse) ArrayList(java.util.ArrayList) DeleteKeyResult(tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeyResult) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) ExternalValidator(tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator)

Aggregations

ArrayList (java.util.ArrayList)1 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1 DeleteKeyResult (tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeyResult)1 DeleteRemoteKeysResponse (tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteRemoteKeysResponse)1 ExternalValidator (tech.pegasys.teku.validator.client.restapi.apis.schema.ExternalValidator)1