forked from Qortal/qortal
Add support for "only one registered name per account" + de-static brokenMD160 blockchain flag
This commit is contained in:
parent
ec5eba9c60
commit
edcbf4f318
@ -84,8 +84,11 @@ public class BlockChain {
|
|||||||
@XmlJavaTypeAdapter(StringLongMapXmlAdapter.class)
|
@XmlJavaTypeAdapter(StringLongMapXmlAdapter.class)
|
||||||
private Map<String, Long> featureTriggers;
|
private Map<String, Long> featureTriggers;
|
||||||
|
|
||||||
// This property is slightly different as we need it early and we want to avoid getInstance() loop
|
/** Whether to use legacy, broken RIPEMD160 implementation when converting public keys to addresses. */
|
||||||
private static boolean useBrokenMD160ForAddresses = false;
|
private boolean useBrokenMD160ForAddresses = false;
|
||||||
|
|
||||||
|
/** Whether only one registered name is allowed per account. */
|
||||||
|
private boolean oneNamePerAccount = false;
|
||||||
|
|
||||||
// Constructors, etc.
|
// Constructors, etc.
|
||||||
|
|
||||||
@ -217,8 +220,12 @@ public class BlockChain {
|
|||||||
return this.defaultGroupId;
|
return this.defaultGroupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getUseBrokenMD160ForAddresses() {
|
public boolean getUseBrokenMD160ForAddresses() {
|
||||||
return useBrokenMD160ForAddresses;
|
return this.useBrokenMD160ForAddresses;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean oneNamePerAccount() {
|
||||||
|
return this.oneNamePerAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convenience methods for specific blockchain feature triggers
|
// Convenience methods for specific blockchain feature triggers
|
||||||
|
@ -50,7 +50,7 @@ public class Crypto {
|
|||||||
byte[] inputHash = digest(input);
|
byte[] inputHash = digest(input);
|
||||||
|
|
||||||
// Use RIPEMD160 to create shorter address
|
// Use RIPEMD160 to create shorter address
|
||||||
if (BlockChain.getUseBrokenMD160ForAddresses()) {
|
if (BlockChain.getInstance().getUseBrokenMD160ForAddresses()) {
|
||||||
// Legacy BROKEN MD160
|
// Legacy BROKEN MD160
|
||||||
BrokenMD160 brokenMD160 = new BrokenMD160();
|
BrokenMD160 brokenMD160 = new BrokenMD160();
|
||||||
inputHash = brokenMD160.digest(inputHash);
|
inputHash = brokenMD160.digest(inputHash);
|
||||||
|
@ -8,6 +8,7 @@ import java.util.List;
|
|||||||
import org.qora.account.Account;
|
import org.qora.account.Account;
|
||||||
import org.qora.account.PublicKeyAccount;
|
import org.qora.account.PublicKeyAccount;
|
||||||
import org.qora.asset.Asset;
|
import org.qora.asset.Asset;
|
||||||
|
import org.qora.block.BlockChain;
|
||||||
import org.qora.crypto.Crypto;
|
import org.qora.crypto.Crypto;
|
||||||
import org.qora.data.transaction.RegisterNameTransactionData;
|
import org.qora.data.transaction.RegisterNameTransactionData;
|
||||||
import org.qora.data.transaction.TransactionData;
|
import org.qora.data.transaction.TransactionData;
|
||||||
@ -75,6 +76,12 @@ public class RegisterNameTransaction extends Transaction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValidationResult isValid() throws DataException {
|
public ValidationResult isValid() throws DataException {
|
||||||
|
Account registrant = getRegistrant();
|
||||||
|
|
||||||
|
// If accounts are only allowed one registered name then check for this
|
||||||
|
if (BlockChain.getInstance().oneNamePerAccount() && !this.repository.getNameRepository().getNamesByOwner(registrant.getAddress()).isEmpty())
|
||||||
|
return ValidationResult.MULTIPLE_NAMES_FORBIDDEN;
|
||||||
|
|
||||||
// Check owner address is valid
|
// Check owner address is valid
|
||||||
if (!Crypto.isValidAddress(registerNameTransactionData.getOwner()))
|
if (!Crypto.isValidAddress(registerNameTransactionData.getOwner()))
|
||||||
return ValidationResult.INVALID_ADDRESS;
|
return ValidationResult.INVALID_ADDRESS;
|
||||||
@ -102,8 +109,6 @@ public class RegisterNameTransaction extends Transaction {
|
|||||||
return ValidationResult.NEGATIVE_FEE;
|
return ValidationResult.NEGATIVE_FEE;
|
||||||
|
|
||||||
// Check reference is correct
|
// Check reference is correct
|
||||||
Account registrant = getRegistrant();
|
|
||||||
|
|
||||||
if (!Arrays.equals(registrant.getLastReference(), registerNameTransactionData.getReference()))
|
if (!Arrays.equals(registrant.getLastReference(), registerNameTransactionData.getReference()))
|
||||||
return ValidationResult.INVALID_REFERENCE;
|
return ValidationResult.INVALID_REFERENCE;
|
||||||
|
|
||||||
|
@ -186,6 +186,7 @@ public abstract class Transaction {
|
|||||||
TRANSACTION_ALREADY_CONFIRMED(66),
|
TRANSACTION_ALREADY_CONFIRMED(66),
|
||||||
INVALID_TX_GROUP_ID(67),
|
INVALID_TX_GROUP_ID(67),
|
||||||
TX_GROUP_ID_MISMATCH(68),
|
TX_GROUP_ID_MISMATCH(68),
|
||||||
|
MULTIPLE_NAMES_FORBIDDEN(69),
|
||||||
NOT_YET_RELEASED(1000);
|
NOT_YET_RELEASED(1000);
|
||||||
|
|
||||||
public final int value;
|
public final int value;
|
||||||
|
@ -31,7 +31,7 @@ public class CryptoTests extends Common {
|
|||||||
@Test
|
@Test
|
||||||
public void testPublicKeyToAddress() {
|
public void testPublicKeyToAddress() {
|
||||||
byte[] publicKey = HashCode.fromString("775ada64a48a30b3bfc4f1db16bca512d4088704975a62bde78781ce0cba90d6").asBytes();
|
byte[] publicKey = HashCode.fromString("775ada64a48a30b3bfc4f1db16bca512d4088704975a62bde78781ce0cba90d6").asBytes();
|
||||||
String expected = BlockChain.getUseBrokenMD160ForAddresses() ? "QUD9y7NZqTtNwvSAUfewd7zKUGoVivVnTW" : "QPc6TvGJ5RjW6LpwUtafx7XRCdRvyN6rsA";
|
String expected = BlockChain.getInstance().getUseBrokenMD160ForAddresses() ? "QUD9y7NZqTtNwvSAUfewd7zKUGoVivVnTW" : "QPc6TvGJ5RjW6LpwUtafx7XRCdRvyN6rsA";
|
||||||
|
|
||||||
assertEquals(expected, Crypto.toAddress(publicKey));
|
assertEquals(expected, Crypto.toAddress(publicKey));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user