forked from Qortal/qortal
Refactor Unicode 'reduced' name code from side-effects into 'data' objects.
CREATE_GROUP, ISSUE_ASSET, REGISTER_NAME and UPDATE_NAME transactions affected. The code to actually generate 'reduced' name was called inside isValid() and relied on setting the corresponding transaction data object field so that it would be saved by isValid()'s caller. Although this worked, it wasn't a very clean solution. Now the 'reduced' name is generated by transaction data object's constructors so it is always present. Also removed name/group/asset reduceName(String) methods as they were all the same single-line call to Unicode.sanitize().
This commit is contained in:
parent
ed178e744d
commit
72100fe1d8
@ -8,7 +8,6 @@ import org.qortal.data.transaction.UpdateAssetTransactionData;
|
|||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
import org.qortal.repository.Repository;
|
import org.qortal.repository.Repository;
|
||||||
import org.qortal.utils.Amounts;
|
import org.qortal.utils.Amounts;
|
||||||
import org.qortal.utils.Unicode;
|
|
||||||
|
|
||||||
public class Asset {
|
public class Asset {
|
||||||
|
|
||||||
@ -68,10 +67,6 @@ public class Asset {
|
|||||||
|
|
||||||
// Processing
|
// Processing
|
||||||
|
|
||||||
public static String reduceName(String assetName) {
|
|
||||||
return Unicode.sanitize(assetName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void issue() throws DataException {
|
public void issue() throws DataException {
|
||||||
this.repository.getAssetRepository().save(this.assetData);
|
this.repository.getAssetRepository().save(this.assetData);
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,9 @@ import javax.xml.bind.annotation.XmlTransient;
|
|||||||
|
|
||||||
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
|
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
|
||||||
import org.qortal.block.GenesisBlock;
|
import org.qortal.block.GenesisBlock;
|
||||||
import org.qortal.group.Group;
|
|
||||||
import org.qortal.group.Group.ApprovalThreshold;
|
import org.qortal.group.Group.ApprovalThreshold;
|
||||||
import org.qortal.transaction.Transaction.TransactionType;
|
import org.qortal.transaction.Transaction.TransactionType;
|
||||||
|
import org.qortal.utils.Unicode;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema.AccessMode;
|
import io.swagger.v3.oas.annotations.media.Schema.AccessMode;
|
||||||
@ -67,7 +67,7 @@ public class CreateGroupTransactionData extends TransactionData {
|
|||||||
* then we need to construct 'reduced' group name.
|
* then we need to construct 'reduced' group name.
|
||||||
*/
|
*/
|
||||||
if (parent instanceof GenesisBlock.GenesisInfo && this.reducedGroupName == null)
|
if (parent instanceof GenesisBlock.GenesisInfo && this.reducedGroupName == null)
|
||||||
this.reducedGroupName = Group.reduceName(this.groupName);
|
this.reducedGroupName = Unicode.sanitize(this.groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** From repository */
|
/** From repository */
|
||||||
@ -91,7 +91,8 @@ public class CreateGroupTransactionData extends TransactionData {
|
|||||||
public CreateGroupTransactionData(BaseTransactionData baseTransactionData,
|
public CreateGroupTransactionData(BaseTransactionData baseTransactionData,
|
||||||
String groupName, String description, boolean isOpen,
|
String groupName, String description, boolean isOpen,
|
||||||
ApprovalThreshold approvalThreshold, int minimumBlockDelay, int maximumBlockDelay) {
|
ApprovalThreshold approvalThreshold, int minimumBlockDelay, int maximumBlockDelay) {
|
||||||
this(baseTransactionData, groupName, description, isOpen, approvalThreshold, minimumBlockDelay, maximumBlockDelay, null, null);
|
this(baseTransactionData, groupName, description, isOpen, approvalThreshold, minimumBlockDelay,
|
||||||
|
maximumBlockDelay, null, Unicode.sanitize(groupName));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters / setters
|
// Getters / setters
|
||||||
@ -132,10 +133,6 @@ public class CreateGroupTransactionData extends TransactionData {
|
|||||||
return this.reducedGroupName;
|
return this.reducedGroupName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReducedGroupName(String reducedGroupName) {
|
|
||||||
this.reducedGroupName = reducedGroupName;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Re-expose creatorPublicKey for this transaction type for JAXB
|
// Re-expose creatorPublicKey for this transaction type for JAXB
|
||||||
@XmlElement(name = "creatorPublicKey")
|
@XmlElement(name = "creatorPublicKey")
|
||||||
@Schema(name = "creatorPublicKey", description = "group creator's public key", example = "2tiMr5LTpaWCgbRvkPK8TFd7k63DyHJMMFFsz9uBf1ZP")
|
@Schema(name = "creatorPublicKey", description = "group creator's public key", example = "2tiMr5LTpaWCgbRvkPK8TFd7k63DyHJMMFFsz9uBf1ZP")
|
||||||
|
@ -8,9 +8,9 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
|||||||
|
|
||||||
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
|
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
|
||||||
import org.qortal.account.NullAccount;
|
import org.qortal.account.NullAccount;
|
||||||
import org.qortal.asset.Asset;
|
|
||||||
import org.qortal.block.GenesisBlock;
|
import org.qortal.block.GenesisBlock;
|
||||||
import org.qortal.transaction.Transaction.TransactionType;
|
import org.qortal.transaction.Transaction.TransactionType;
|
||||||
|
import org.qortal.utils.Unicode;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema.AccessMode;
|
import io.swagger.v3.oas.annotations.media.Schema.AccessMode;
|
||||||
@ -76,7 +76,7 @@ public class IssueAssetTransactionData extends TransactionData {
|
|||||||
* then we need to construct 'reduced' form of asset name.
|
* then we need to construct 'reduced' form of asset name.
|
||||||
*/
|
*/
|
||||||
if (parent instanceof GenesisBlock.GenesisInfo && this.reducedAssetName == null)
|
if (parent instanceof GenesisBlock.GenesisInfo && this.reducedAssetName == null)
|
||||||
this.reducedAssetName = Asset.reduceName(this.assetName);
|
this.reducedAssetName = Unicode.sanitize(this.assetName);
|
||||||
|
|
||||||
this.creatorPublicKey = this.issuerPublicKey;
|
this.creatorPublicKey = this.issuerPublicKey;
|
||||||
}
|
}
|
||||||
@ -101,7 +101,8 @@ public class IssueAssetTransactionData extends TransactionData {
|
|||||||
/** From network/API */
|
/** From network/API */
|
||||||
public IssueAssetTransactionData(BaseTransactionData baseTransactionData, String assetName, String description,
|
public IssueAssetTransactionData(BaseTransactionData baseTransactionData, String assetName, String description,
|
||||||
long quantity, boolean isDivisible, String data, boolean isUnspendable) {
|
long quantity, boolean isDivisible, String data, boolean isUnspendable) {
|
||||||
this(baseTransactionData, null, assetName, description, quantity, isDivisible, data, isUnspendable, null);
|
this(baseTransactionData, null, assetName, description, quantity, isDivisible, data, isUnspendable,
|
||||||
|
Unicode.sanitize(assetName));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters/Setters
|
// Getters/Setters
|
||||||
@ -146,8 +147,4 @@ public class IssueAssetTransactionData extends TransactionData {
|
|||||||
return this.reducedAssetName;
|
return this.reducedAssetName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReducedAssetName(String reducedAssetName) {
|
|
||||||
this.reducedAssetName = reducedAssetName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
|||||||
import javax.xml.bind.annotation.XmlTransient;
|
import javax.xml.bind.annotation.XmlTransient;
|
||||||
|
|
||||||
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
|
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
|
||||||
import org.qortal.naming.Name;
|
|
||||||
import org.qortal.transaction.Transaction.TransactionType;
|
import org.qortal.transaction.Transaction.TransactionType;
|
||||||
|
import org.qortal.utils.Unicode;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ public class RegisterNameTransactionData extends TransactionData {
|
|||||||
|
|
||||||
/** From network */
|
/** From network */
|
||||||
public RegisterNameTransactionData(BaseTransactionData baseTransactionData, String name, String data) {
|
public RegisterNameTransactionData(BaseTransactionData baseTransactionData, String name, String data) {
|
||||||
this(baseTransactionData, name, data, Name.reduceName(name));
|
this(baseTransactionData, name, data, Unicode.sanitize(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters / setters
|
// Getters / setters
|
||||||
@ -78,8 +78,4 @@ public class RegisterNameTransactionData extends TransactionData {
|
|||||||
return this.reducedName;
|
return this.reducedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReducedName(String reducedName) {
|
|
||||||
this.reducedName = reducedName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ import javax.xml.bind.annotation.XmlAccessType;
|
|||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
import javax.xml.bind.annotation.XmlTransient;
|
import javax.xml.bind.annotation.XmlTransient;
|
||||||
|
|
||||||
import org.qortal.naming.Name;
|
|
||||||
import org.qortal.transaction.Transaction.TransactionType;
|
import org.qortal.transaction.Transaction.TransactionType;
|
||||||
|
import org.qortal.utils.Unicode;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ public class UpdateNameTransactionData extends TransactionData {
|
|||||||
|
|
||||||
/** From network/API */
|
/** From network/API */
|
||||||
public UpdateNameTransactionData(BaseTransactionData baseTransactionData, String name, String newName, String newData) {
|
public UpdateNameTransactionData(BaseTransactionData baseTransactionData, String name, String newName, String newData) {
|
||||||
this(baseTransactionData, name, newName, newData, Name.reduceName(newName), null);
|
this(baseTransactionData, name, newName, newData, Unicode.sanitize(newName), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters / setters
|
// Getters / setters
|
||||||
@ -89,10 +89,6 @@ public class UpdateNameTransactionData extends TransactionData {
|
|||||||
return this.reducedNewName;
|
return this.reducedNewName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReducedNewName(String reducedNewName) {
|
|
||||||
this.reducedNewName = reducedNewName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getNameReference() {
|
public byte[] getNameReference() {
|
||||||
return this.nameReference;
|
return this.nameReference;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ import org.qortal.data.transaction.UpdateGroupTransactionData;
|
|||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
import org.qortal.repository.GroupRepository;
|
import org.qortal.repository.GroupRepository;
|
||||||
import org.qortal.repository.Repository;
|
import org.qortal.repository.Repository;
|
||||||
import org.qortal.utils.Unicode;
|
|
||||||
|
|
||||||
public class Group {
|
public class Group {
|
||||||
|
|
||||||
@ -128,12 +127,6 @@ public class Group {
|
|||||||
return this.groupData;
|
return this.groupData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shortcuts to aid code clarity
|
|
||||||
|
|
||||||
public static String reduceName(String name) {
|
|
||||||
return Unicode.sanitize(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Membership
|
// Membership
|
||||||
|
|
||||||
private GroupMemberData getMember(String member) throws DataException {
|
private GroupMemberData getMember(String member) throws DataException {
|
||||||
|
@ -60,10 +60,6 @@ public class Name {
|
|||||||
|
|
||||||
// Processing
|
// Processing
|
||||||
|
|
||||||
public static String reduceName(String name) {
|
|
||||||
return Unicode.sanitize(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void register() throws DataException {
|
public void register() throws DataException {
|
||||||
this.repository.getNameRepository().save(this.nameData);
|
this.repository.getNameRepository().save(this.nameData);
|
||||||
}
|
}
|
||||||
|
@ -40,15 +40,6 @@ public class CreateGroupTransaction extends Transaction {
|
|||||||
return this.getCreator();
|
return this.getCreator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized String getReducedGroupName() {
|
|
||||||
if (this.createGroupTransactionData.getReducedGroupName() == null) {
|
|
||||||
String reducedGroupName = Group.reduceName(this.createGroupTransactionData.getGroupName());
|
|
||||||
this.createGroupTransactionData.setReducedGroupName(reducedGroupName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.createGroupTransactionData.getReducedGroupName();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Processing
|
// Processing
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -89,16 +80,13 @@ public class CreateGroupTransaction extends Transaction {
|
|||||||
if (creator.getConfirmedBalance(Asset.QORT) < this.createGroupTransactionData.getFee())
|
if (creator.getConfirmedBalance(Asset.QORT) < this.createGroupTransactionData.getFee())
|
||||||
return ValidationResult.NO_BALANCE;
|
return ValidationResult.NO_BALANCE;
|
||||||
|
|
||||||
// Fill in missing reduced name. Caller is likely to save this as next step.
|
|
||||||
getReducedGroupName();
|
|
||||||
|
|
||||||
return ValidationResult.OK;
|
return ValidationResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValidationResult isProcessable() throws DataException {
|
public ValidationResult isProcessable() throws DataException {
|
||||||
// Check the group name isn't already taken
|
// Check the group name isn't already taken
|
||||||
if (this.repository.getGroupRepository().reducedGroupNameExists(getReducedGroupName()))
|
if (this.repository.getGroupRepository().reducedGroupNameExists(this.createGroupTransactionData.getReducedGroupName()))
|
||||||
return ValidationResult.GROUP_ALREADY_EXISTS;
|
return ValidationResult.GROUP_ALREADY_EXISTS;
|
||||||
|
|
||||||
return ValidationResult.OK;
|
return ValidationResult.OK;
|
||||||
|
@ -7,7 +7,6 @@ import org.qortal.account.Account;
|
|||||||
import org.qortal.asset.Asset;
|
import org.qortal.asset.Asset;
|
||||||
import org.qortal.data.transaction.IssueAssetTransactionData;
|
import org.qortal.data.transaction.IssueAssetTransactionData;
|
||||||
import org.qortal.data.transaction.TransactionData;
|
import org.qortal.data.transaction.TransactionData;
|
||||||
import org.qortal.naming.Name;
|
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
import org.qortal.repository.Repository;
|
import org.qortal.repository.Repository;
|
||||||
import org.qortal.utils.Amounts;
|
import org.qortal.utils.Amounts;
|
||||||
@ -42,15 +41,6 @@ public class IssueAssetTransaction extends Transaction {
|
|||||||
return this.getCreator();
|
return this.getCreator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getReducedAssetName() {
|
|
||||||
if (this.issueAssetTransactionData.getReducedAssetName() == null) {
|
|
||||||
String reducedAssetName = Name.reduceName(this.issueAssetTransactionData.getAssetName());
|
|
||||||
this.issueAssetTransactionData.setReducedAssetName(reducedAssetName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.issueAssetTransactionData.getReducedAssetName();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Processing
|
// Processing
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -90,16 +80,13 @@ public class IssueAssetTransaction extends Transaction {
|
|||||||
if (issuer.getConfirmedBalance(Asset.QORT) < this.issueAssetTransactionData.getFee())
|
if (issuer.getConfirmedBalance(Asset.QORT) < this.issueAssetTransactionData.getFee())
|
||||||
return ValidationResult.NO_BALANCE;
|
return ValidationResult.NO_BALANCE;
|
||||||
|
|
||||||
// Fill in missing reduced name. Caller is likely to save this as next step.
|
|
||||||
getReducedAssetName();
|
|
||||||
|
|
||||||
return ValidationResult.OK;
|
return ValidationResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValidationResult isProcessable() throws DataException {
|
public ValidationResult isProcessable() throws DataException {
|
||||||
// Check the name isn't already taken
|
// Check the name isn't already taken
|
||||||
if (this.repository.getAssetRepository().reducedAssetNameExists(getReducedAssetName()))
|
if (this.repository.getAssetRepository().reducedAssetNameExists(this.issueAssetTransactionData.getReducedAssetName()))
|
||||||
return ValidationResult.ASSET_ALREADY_EXISTS;
|
return ValidationResult.ASSET_ALREADY_EXISTS;
|
||||||
|
|
||||||
return ValidationResult.OK;
|
return ValidationResult.OK;
|
||||||
|
@ -41,15 +41,6 @@ public class RegisterNameTransaction extends Transaction {
|
|||||||
return this.getCreator();
|
return this.getCreator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized String getReducedName() {
|
|
||||||
if (this.registerNameTransactionData.getReducedName() == null) {
|
|
||||||
String reducedName = Name.reduceName(this.registerNameTransactionData.getName());
|
|
||||||
this.registerNameTransactionData.setReducedName(reducedName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.registerNameTransactionData.getReducedName();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Processing
|
// Processing
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -75,16 +66,13 @@ public class RegisterNameTransaction extends Transaction {
|
|||||||
if (registrant.getConfirmedBalance(Asset.QORT) < this.registerNameTransactionData.getFee())
|
if (registrant.getConfirmedBalance(Asset.QORT) < this.registerNameTransactionData.getFee())
|
||||||
return ValidationResult.NO_BALANCE;
|
return ValidationResult.NO_BALANCE;
|
||||||
|
|
||||||
// Fill in missing reduced name. Caller is likely to save this as next step.
|
|
||||||
getReducedName();
|
|
||||||
|
|
||||||
return ValidationResult.OK;
|
return ValidationResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ValidationResult isProcessable() throws DataException {
|
public ValidationResult isProcessable() throws DataException {
|
||||||
// Check the name isn't already taken
|
// Check the name isn't already taken
|
||||||
if (this.repository.getNameRepository().reducedNameExists(getReducedName()))
|
if (this.repository.getNameRepository().reducedNameExists(this.registerNameTransactionData.getReducedName()))
|
||||||
return ValidationResult.NAME_ALREADY_REGISTERED;
|
return ValidationResult.NAME_ALREADY_REGISTERED;
|
||||||
|
|
||||||
// If accounts are only allowed one registered name then check for this
|
// If accounts are only allowed one registered name then check for this
|
||||||
|
@ -41,15 +41,6 @@ public class UpdateNameTransaction extends Transaction {
|
|||||||
return this.getCreator();
|
return this.getCreator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized String getReducedNewName() {
|
|
||||||
if (this.updateNameTransactionData.getReducedNewName() == null) {
|
|
||||||
String reducedNewName = Name.reduceName(this.updateNameTransactionData.getNewName());
|
|
||||||
this.updateNameTransactionData.setReducedNewName(reducedNewName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.updateNameTransactionData.getReducedNewName();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Processing
|
// Processing
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -99,9 +90,6 @@ public class UpdateNameTransaction extends Transaction {
|
|||||||
if (owner.getConfirmedBalance(Asset.QORT) < this.updateNameTransactionData.getFee())
|
if (owner.getConfirmedBalance(Asset.QORT) < this.updateNameTransactionData.getFee())
|
||||||
return ValidationResult.NO_BALANCE;
|
return ValidationResult.NO_BALANCE;
|
||||||
|
|
||||||
// Fill in missing reduced new name. Caller is likely to save this as next step.
|
|
||||||
getReducedNewName();
|
|
||||||
|
|
||||||
return ValidationResult.OK;
|
return ValidationResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +112,7 @@ public class UpdateNameTransaction extends Transaction {
|
|||||||
return ValidationResult.INVALID_NAME_OWNER;
|
return ValidationResult.INVALID_NAME_OWNER;
|
||||||
|
|
||||||
// Check new name isn't already taken, unless it is the same name (this allows for case-adjusting renames)
|
// Check new name isn't already taken, unless it is the same name (this allows for case-adjusting renames)
|
||||||
NameData newNameData = this.repository.getNameRepository().fromReducedName(getReducedNewName());
|
NameData newNameData = this.repository.getNameRepository().fromReducedName(this.updateNameTransactionData.getReducedNewName());
|
||||||
if (newNameData != null && !newNameData.getName().equals(nameData.getName()))
|
if (newNameData != null && !newNameData.getName().equals(nameData.getName()))
|
||||||
return ValidationResult.NAME_ALREADY_REGISTERED;
|
return ValidationResult.NAME_ALREADY_REGISTERED;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user