forked from Qortal/qortal
Restrict TRANSFER_PRIVS recipients to new (non-existent) accounts.
This commit is contained in:
parent
450ff7318f
commit
a3c44428d3
@ -241,6 +241,7 @@ public abstract class Transaction {
|
||||
ASSET_NOT_SPENDABLE(89),
|
||||
ACCOUNT_CANNOT_REWARD_SHARE(90),
|
||||
SELF_SHARE_EXISTS(91),
|
||||
ACCOUNT_ALREADY_EXISTS(92),
|
||||
NOT_YET_RELEASED(1000);
|
||||
|
||||
public final int value;
|
||||
|
@ -83,6 +83,10 @@ public class TransferPrivsTransaction extends Transaction {
|
||||
if (!Crypto.isValidAddress(this.transferPrivsTransactionData.getRecipient()))
|
||||
return ValidationResult.INVALID_ADDRESS;
|
||||
|
||||
// Check recipient is new account
|
||||
if (this.repository.getAccountRepository().accountExists(this.transferPrivsTransactionData.getRecipient()))
|
||||
return ValidationResult.ACCOUNT_ALREADY_EXISTS;
|
||||
|
||||
return ValidationResult.OK;
|
||||
}
|
||||
|
||||
@ -183,8 +187,11 @@ public class TransferPrivsTransaction extends Transaction {
|
||||
accountRepository.setFlags(senderData);
|
||||
|
||||
// Restore recipient's flags
|
||||
recipientData.setFlags(this.transferPrivsTransactionData.getPreviousRecipientFlags());
|
||||
accountRepository.setFlags(recipientData);
|
||||
Integer previousRecipientFlags = this.transferPrivsTransactionData.getPreviousRecipientFlags();
|
||||
if (previousRecipientFlags != null) {
|
||||
recipientData.setFlags(previousRecipientFlags);
|
||||
accountRepository.setFlags(recipientData);
|
||||
}
|
||||
|
||||
// Clean values in transaction data
|
||||
this.transferPrivsTransactionData.setPreviousSenderFlags(null);
|
||||
|
@ -5,6 +5,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.qortal.account.Account;
|
||||
import org.qortal.account.PrivateKeyAccount;
|
||||
import org.qortal.account.PublicKeyAccount;
|
||||
import org.qortal.block.BlockChain;
|
||||
import org.qortal.block.BlockMinter;
|
||||
import org.qortal.data.account.AccountData;
|
||||
@ -19,11 +20,13 @@ import org.qortal.test.common.BlockUtils;
|
||||
import org.qortal.test.common.Common;
|
||||
import org.qortal.test.common.TestAccount;
|
||||
import org.qortal.test.common.TransactionUtils;
|
||||
import org.qortal.transform.Transformer;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class TransferPrivsTests extends Common {
|
||||
|
||||
@ -42,6 +45,27 @@ public class TransferPrivsTests extends Common {
|
||||
Common.orphanCheck();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliceIntoNewAccountTransferPrivs() throws DataException {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
TestAccount alice = Common.getTestAccount(repository, "alice");
|
||||
assertTrue(alice.canMint());
|
||||
|
||||
PrivateKeyAccount aliceMintingAccount = Common.getTestAccount(repository, "alice-reward-share");
|
||||
|
||||
byte[] randomPublicKey = new byte[Transformer.PUBLIC_KEY_LENGTH];
|
||||
Random random = new Random();
|
||||
random.nextBytes(randomPublicKey);
|
||||
|
||||
Account randomAccount = new PublicKeyAccount(repository, randomPublicKey);
|
||||
|
||||
combineAccounts(repository, alice, randomAccount, aliceMintingAccount);
|
||||
|
||||
assertFalse(alice.canMint());
|
||||
assertTrue(randomAccount.canMint());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAliceIntoDilbertTransferPrivs() throws DataException {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
Loading…
Reference in New Issue
Block a user