Allow minting accounts to be removed from node using public key as well as private key

This commit is contained in:
catbref 2020-07-28 10:45:06 +01:00
parent 340d6dfc8d
commit 6c182a3567
4 changed files with 22 additions and 9 deletions

View File

@ -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();

View File

@ -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));
}
}

View File

@ -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

View File

@ -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);
}