From 6c182a356718c5e9e2f3526e482e27bf5c3f20ab Mon Sep 17 00:00:00 2001 From: catbref Date: Tue, 28 Jul 2020 10:45:06 +0100 Subject: [PATCH] Allow minting accounts to be removed from node using public key as well as private key --- .../java/org/qortal/api/resource/AdminResource.java | 10 +++++----- .../org/qortal/data/account/RewardShareData.java | 13 +++++++++++++ .../org/qortal/repository/AccountRepository.java | 4 ++-- .../repository/hsqldb/HSQLDBAccountRepository.java | 4 ++-- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/qortal/api/resource/AdminResource.java b/src/main/java/org/qortal/api/resource/AdminResource.java index 9b765f40..7b07551a 100644 --- a/src/main/java/org/qortal/api/resource/AdminResource.java +++ b/src/main/java/org/qortal/api/resource/AdminResource.java @@ -302,13 +302,13 @@ public class AdminResource { @DELETE @Path("/mintingaccounts") @Operation( - summary = "Remove account/reward-share from use by BlockMinter, using private key", + summary = "Remove account/reward-share from use by BlockMinter, using public or private key", requestBody = @RequestBody( required = true, content = @Content( mediaType = MediaType.TEXT_PLAIN, schema = @Schema( - type = "string", example = "private key" + type = "string", example = "public or private key" ) ) ), @@ -319,13 +319,13 @@ public class AdminResource { } ) @ApiErrors({ApiError.INVALID_PRIVATE_KEY, ApiError.REPOSITORY_ISSUE}) - public String deleteMintingAccount(String seed58) { + public String deleteMintingAccount(String key58) { Security.checkApiCallAllowed(request); try (final Repository repository = RepositoryManager.getRepository()) { - byte[] seed = Base58.decode(seed58.trim()); + byte[] key = Base58.decode(key58.trim()); - if (repository.getAccountRepository().delete(seed) == 0) + if (repository.getAccountRepository().delete(key) == 0) return "false"; repository.saveChanges(); diff --git a/src/main/java/org/qortal/data/account/RewardShareData.java b/src/main/java/org/qortal/data/account/RewardShareData.java index c68e4257..ead1bbd9 100644 --- a/src/main/java/org/qortal/data/account/RewardShareData.java +++ b/src/main/java/org/qortal/data/account/RewardShareData.java @@ -1,11 +1,15 @@ package org.qortal.data.account; +import java.math.BigDecimal; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import org.qortal.utils.Base58; + import io.swagger.v3.oas.annotations.media.Schema; // All properties to be converted to JSON via JAXB @@ -71,4 +75,13 @@ public class RewardShareData { return this.minter; } + // For debugging + + public String toString() { + if (this.minter.equals(this.recipient)) + return String.format("Minter/recipient: %s, reward-share public key: %s", this.minter, Base58.encode(this.rewardSharePublicKey)); + else + return String.format("Minter: %s, recipient: %s (%s %%), reward-share public key: %s", this.minter, this.recipient, BigDecimal.valueOf(this.sharePercent, 2), Base58.encode(this.rewardSharePublicKey)); + } + } diff --git a/src/main/java/org/qortal/repository/AccountRepository.java b/src/main/java/org/qortal/repository/AccountRepository.java index f6997fae..1c96f2fa 100644 --- a/src/main/java/org/qortal/repository/AccountRepository.java +++ b/src/main/java/org/qortal/repository/AccountRepository.java @@ -169,8 +169,8 @@ public interface AccountRepository { public void save(MintingAccountData mintingAccountData) throws DataException; - /** Delete minting account info, used by BlockMinter, from repository using passed private key. */ - public int delete(byte[] mintingAccountPrivateKey) throws DataException; + /** Delete minting account info, used by BlockMinter, from repository using passed public or private key. */ + public int delete(byte[] mintingAccountKey) throws DataException; // Managing QORT from legacy QORA diff --git a/src/main/java/org/qortal/repository/hsqldb/HSQLDBAccountRepository.java b/src/main/java/org/qortal/repository/hsqldb/HSQLDBAccountRepository.java index 928a251b..38862ef6 100644 --- a/src/main/java/org/qortal/repository/hsqldb/HSQLDBAccountRepository.java +++ b/src/main/java/org/qortal/repository/hsqldb/HSQLDBAccountRepository.java @@ -774,9 +774,9 @@ public class HSQLDBAccountRepository implements AccountRepository { } @Override - public int delete(byte[] minterPrivateKey) throws DataException { + public int delete(byte[] minterKey) throws DataException { try { - return this.repository.delete("MintingAccounts", "minter_private_key = ?", minterPrivateKey); + return this.repository.delete("MintingAccounts", "minter_private_key = ? OR minter_public_key = ?", minterKey, minterKey); } catch (SQLException e) { throw new DataException("Unable to delete minting account from repository", e); }