Fix incorrect declared transaction length for SET_GROUP and VOTE_ON_POLL transactions.

Added transaction [de]serialization test, along with corresponding random transaction generators.

Minor typo fix in Transaction.

Minor clarification in MessageTransactionTransformer.

Added debugging to Account.
This commit is contained in:
catbref
2019-06-11 11:27:52 +01:00
parent 02e8bdb034
commit 03f60ef898
48 changed files with 881 additions and 174 deletions

View File

@@ -16,6 +16,7 @@ import org.qora.repository.BlockRepository;
import org.qora.repository.DataException;
import org.qora.repository.Repository;
import org.qora.transaction.Transaction;
import org.qora.utils.Base58;
public class Account {
@@ -159,7 +160,9 @@ public class Account {
* @throws DataException
*/
public byte[] getLastReference() throws DataException {
return this.repository.getAccountRepository().getLastReference(this.address);
byte[] reference = this.repository.getAccountRepository().getLastReference(this.address);
LOGGER.trace(() -> String.format("Last reference for %s is %s", this.address, reference == null ? "null" : Base58.encode(reference)));
return reference;
}
/**
@@ -184,6 +187,8 @@ public class Account {
reference = transactionData.getSignature();
}
final byte[] loggingReference = reference;
LOGGER.trace(() -> String.format("Last unconfirmed reference for %s is %s", this.address, loggingReference == null ? "null" : Base58.encode(loggingReference)));
return reference;
}
@@ -195,6 +200,8 @@ public class Account {
* @throws DataException
*/
public void setLastReference(byte[] reference) throws DataException {
LOGGER.trace(() -> String.format("Setting last reference for %s to %s", this.address, Base58.encode(reference)));
AccountData accountData = this.buildAccountData();
accountData.setReference(reference);
this.repository.getAccountRepository().setLastReference(accountData);

View File

@@ -562,7 +562,7 @@ public abstract class Transaction {
if (!this.hasValidReference())
return ValidationResult.INVALID_REFERENCE;
// Check transction is processable
// Check transaction is processable
result = this.isProcessable();
return result;

View File

@@ -28,7 +28,7 @@ public class MessageTransactionTransformer extends TransactionTransformer {
private static final int IS_TEXT_LENGTH = BOOLEAN_LENGTH;
private static final int IS_ENCRYPTED_LENGTH = BOOLEAN_LENGTH;
private static final int EXTRAS_LENGTH = RECIPIENT_LENGTH + AMOUNT_LENGTH + DATA_SIZE_LENGTH + IS_TEXT_LENGTH + IS_ENCRYPTED_LENGTH;
private static final int EXTRAS_LENGTH = RECIPIENT_LENGTH + AMOUNT_LENGTH + DATA_SIZE_LENGTH + IS_ENCRYPTED_LENGTH + IS_TEXT_LENGTH;
protected static final TransactionLayout layout;
@@ -99,7 +99,7 @@ public class MessageTransactionTransformer extends TransactionTransformer {
public static int getDataLength(TransactionData transactionData) throws TransformationException {
MessageTransactionData messageTransactionData = (MessageTransactionData) transactionData;
int dataLength = getBaseLength(transactionData) + EXTRAS_LENGTH;
int dataLength = getBaseLength(transactionData) + EXTRAS_LENGTH + messageTransactionData.getData().length;
// V3+ has assetID for amount
if (messageTransactionData.getVersion() != 1)

View File

@@ -18,7 +18,7 @@ import com.google.common.primitives.Ints;
public class SetGroupTransactionTransformer extends TransactionTransformer {
// Property lengths
private static final int GROUPID_LENGTH = SIGNATURE_LENGTH;
private static final int GROUPID_LENGTH = INT_LENGTH;
private static final int EXTRAS_LENGTH = GROUPID_LENGTH;

View File

@@ -20,10 +20,10 @@ import com.google.common.primitives.Ints;
public class VoteOnPollTransactionTransformer extends TransactionTransformer {
// Property lengths
private static final int VOTER_LENGTH = ADDRESS_LENGTH;
private static final int NAME_SIZE_LENGTH = INT_LENGTH;
private static final int POLL_OPTION_LENGTH = INT_LENGTH;
private static final int EXTRAS_LENGTH = VOTER_LENGTH + NAME_SIZE_LENGTH;
private static final int EXTRAS_LENGTH = NAME_SIZE_LENGTH + POLL_OPTION_LENGTH;
protected static final TransactionLayout layout;