forked from Qortal/qortal
Fix up CREATE_POLL and VOTE_ON_POLL transactions to process and validate.
Added rule to enforce that a poll creator is also its owner.
This commit is contained in:
parent
0b8fcc0a7b
commit
1abceada20
@ -2,9 +2,11 @@ package org.qortal.data.transaction;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.xml.bind.Unmarshaller;
|
||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
|
||||||
|
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
|
||||||
import org.qortal.data.voting.PollOptionData;
|
import org.qortal.data.voting.PollOptionData;
|
||||||
import org.qortal.transaction.Transaction;
|
import org.qortal.transaction.Transaction;
|
||||||
import org.qortal.transaction.Transaction.TransactionType;
|
import org.qortal.transaction.Transaction.TransactionType;
|
||||||
@ -14,8 +16,13 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
// All properties to be converted to JSON via JAXB
|
// All properties to be converted to JSON via JAXB
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
@Schema(allOf = { TransactionData.class })
|
@Schema(allOf = { TransactionData.class })
|
||||||
|
@XmlDiscriminatorValue("CREATE_POLL")
|
||||||
public class CreatePollTransactionData extends TransactionData {
|
public class CreatePollTransactionData extends TransactionData {
|
||||||
|
|
||||||
|
|
||||||
|
@Schema(description = "Poll creator's public key", example = "2tiMr5LTpaWCgbRvkPK8TFd7k63DyHJMMFFsz9uBf1ZP")
|
||||||
|
private byte[] pollCreatorPublicKey;
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
private String owner;
|
private String owner;
|
||||||
private String pollName;
|
private String pollName;
|
||||||
@ -29,10 +36,15 @@ public class CreatePollTransactionData extends TransactionData {
|
|||||||
super(TransactionType.CREATE_POLL);
|
super(TransactionType.CREATE_POLL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void afterUnmarshal(Unmarshaller u, Object parent) {
|
||||||
|
this.creatorPublicKey = this.pollCreatorPublicKey;
|
||||||
|
}
|
||||||
|
|
||||||
public CreatePollTransactionData(BaseTransactionData baseTransactionData,
|
public CreatePollTransactionData(BaseTransactionData baseTransactionData,
|
||||||
String owner, String pollName, String description, List<PollOptionData> pollOptions) {
|
String owner, String pollName, String description, List<PollOptionData> pollOptions) {
|
||||||
super(Transaction.TransactionType.CREATE_POLL, baseTransactionData);
|
super(Transaction.TransactionType.CREATE_POLL, baseTransactionData);
|
||||||
|
|
||||||
|
this.creatorPublicKey = baseTransactionData.creatorPublicKey;
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.pollName = pollName;
|
this.pollName = pollName;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@ -41,6 +53,7 @@ public class CreatePollTransactionData extends TransactionData {
|
|||||||
|
|
||||||
// Getters/setters
|
// Getters/setters
|
||||||
|
|
||||||
|
public byte[] getPollCreatorPublicKey() { return this.creatorPublicKey; }
|
||||||
public String getOwner() {
|
public String getOwner() {
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import javax.xml.bind.Unmarshaller;
|
|||||||
import javax.xml.bind.annotation.XmlAccessType;
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
import javax.xml.bind.annotation.XmlAccessorType;
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
|
||||||
|
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
|
||||||
import org.qortal.transaction.Transaction.TransactionType;
|
import org.qortal.transaction.Transaction.TransactionType;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
@ -11,9 +12,11 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
// All properties to be converted to JSON via JAXB
|
// All properties to be converted to JSON via JAXB
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
@Schema(allOf = { TransactionData.class })
|
@Schema(allOf = { TransactionData.class })
|
||||||
|
@XmlDiscriminatorValue("VOTE_ON_POLL")
|
||||||
public class VoteOnPollTransactionData extends TransactionData {
|
public class VoteOnPollTransactionData extends TransactionData {
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
|
@Schema(description = "Vote creator's public key", example = "2tiMr5LTpaWCgbRvkPK8TFd7k63DyHJMMFFsz9uBf1ZP")
|
||||||
private byte[] voterPublicKey;
|
private byte[] voterPublicKey;
|
||||||
private String pollName;
|
private String pollName;
|
||||||
private int optionIndex;
|
private int optionIndex;
|
||||||
|
@ -51,6 +51,21 @@ public class CreatePollTransaction extends Transaction {
|
|||||||
if (!Crypto.isValidAddress(this.createPollTransactionData.getOwner()))
|
if (!Crypto.isValidAddress(this.createPollTransactionData.getOwner()))
|
||||||
return ValidationResult.INVALID_ADDRESS;
|
return ValidationResult.INVALID_ADDRESS;
|
||||||
|
|
||||||
|
Account creator = getCreator();
|
||||||
|
Account owner = getOwner();
|
||||||
|
|
||||||
|
String creatorAddress = creator.getAddress();
|
||||||
|
String ownerAddress = owner.getAddress();
|
||||||
|
|
||||||
|
// Check Owner address is the same as the creator public key
|
||||||
|
if (!creatorAddress.equals(ownerAddress)) {
|
||||||
|
return ValidationResult.INVALID_ADDRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check creator has enough funds
|
||||||
|
if (creator.getConfirmedBalance(Asset.QORT) < this.createPollTransactionData.getFee())
|
||||||
|
return ValidationResult.NO_BALANCE;
|
||||||
|
|
||||||
// Check name size bounds
|
// Check name size bounds
|
||||||
String pollName = this.createPollTransactionData.getPollName();
|
String pollName = this.createPollTransactionData.getPollName();
|
||||||
int pollNameLength = Utf8.encodedLength(pollName);
|
int pollNameLength = Utf8.encodedLength(pollName);
|
||||||
@ -88,12 +103,6 @@ public class CreatePollTransaction extends Transaction {
|
|||||||
optionNames.add(pollOptionData.getOptionName());
|
optionNames.add(pollOptionData.getOptionName());
|
||||||
}
|
}
|
||||||
|
|
||||||
Account creator = getCreator();
|
|
||||||
|
|
||||||
// Check creator has enough funds
|
|
||||||
if (creator.getConfirmedBalance(Asset.QORT) < this.createPollTransactionData.getFee())
|
|
||||||
return ValidationResult.NO_BALANCE;
|
|
||||||
|
|
||||||
return ValidationResult.OK;
|
return ValidationResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user