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:
DrewMPeacock 2022-09-09 11:20:46 -06:00
parent 0b8fcc0a7b
commit 1abceada20
3 changed files with 31 additions and 6 deletions

View File

@ -2,9 +2,11 @@ package org.qortal.data.transaction;
import java.util.List;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
import org.qortal.data.voting.PollOptionData;
import org.qortal.transaction.Transaction;
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
@XmlAccessorType(XmlAccessType.FIELD)
@Schema(allOf = { TransactionData.class })
@XmlDiscriminatorValue("CREATE_POLL")
public class CreatePollTransactionData extends TransactionData {
@Schema(description = "Poll creator's public key", example = "2tiMr5LTpaWCgbRvkPK8TFd7k63DyHJMMFFsz9uBf1ZP")
private byte[] pollCreatorPublicKey;
// Properties
private String owner;
private String pollName;
@ -29,10 +36,15 @@ public class CreatePollTransactionData extends TransactionData {
super(TransactionType.CREATE_POLL);
}
public void afterUnmarshal(Unmarshaller u, Object parent) {
this.creatorPublicKey = this.pollCreatorPublicKey;
}
public CreatePollTransactionData(BaseTransactionData baseTransactionData,
String owner, String pollName, String description, List<PollOptionData> pollOptions) {
super(Transaction.TransactionType.CREATE_POLL, baseTransactionData);
this.creatorPublicKey = baseTransactionData.creatorPublicKey;
this.owner = owner;
this.pollName = pollName;
this.description = description;
@ -41,6 +53,7 @@ public class CreatePollTransactionData extends TransactionData {
// Getters/setters
public byte[] getPollCreatorPublicKey() { return this.creatorPublicKey; }
public String getOwner() {
return this.owner;
}

View File

@ -4,6 +4,7 @@ import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import org.eclipse.persistence.oxm.annotations.XmlDiscriminatorValue;
import org.qortal.transaction.Transaction.TransactionType;
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
@XmlAccessorType(XmlAccessType.FIELD)
@Schema(allOf = { TransactionData.class })
@XmlDiscriminatorValue("VOTE_ON_POLL")
public class VoteOnPollTransactionData extends TransactionData {
// Properties
@Schema(description = "Vote creator's public key", example = "2tiMr5LTpaWCgbRvkPK8TFd7k63DyHJMMFFsz9uBf1ZP")
private byte[] voterPublicKey;
private String pollName;
private int optionIndex;

View File

@ -51,6 +51,21 @@ public class CreatePollTransaction extends Transaction {
if (!Crypto.isValidAddress(this.createPollTransactionData.getOwner()))
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
String pollName = this.createPollTransactionData.getPollName();
int pollNameLength = Utf8.encodedLength(pollName);
@ -88,12 +103,6 @@ public class CreatePollTransaction extends Transaction {
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;
}