From dbbdb6783341a30dda099e53df7f05bc345d2080 Mon Sep 17 00:00:00 2001 From: KovacZan <39158639+KovacZan@users.noreply.github.com> Date: Mon, 9 Mar 2020 14:12:04 +0100 Subject: [PATCH] refactor: java-crypto to follow builder/serializer improvements from latest arkecosystem/crypto changes (#112) * refactor: Serialized class * refactor: Deserialize class * refactor: Added abstract getTransactionInstance method to AbstractTransactionBuilder class * fix: vendorField deserialization * refactor: Transfer transaction * refactor: Abstract transaction * refactor: vote transaction * fix: TransferBuilder - added missing expiration function * refactor: SecondSignatureRegistration * refactor: ipfs transaction type * refactor: MultiPayment test * test: added IpfsBuilder test * refactor: HtlcRefund Transaction * refactor: HtlcLock Transaction * refactor: HtlcClaim Transaction * refactor: relegate resignation transaction * test: add secondVerify check to MultiPaymentBuilderTest * refactor: Delegate Registration transaction * style: apply spotless * refactor: deprecate MultiSignatureRegistration transaction * refactor: remove Fee configuration class * refactor: set default transaction amount to 0 * refactor: fees are now added in type specific builder constructors * style: apply spotlles plugin * refactor: added assetToHashMap method * style: rename assetHaspMap method to assetToHashMap * refactor: made asset classes static * test: added HtlcLock serializer tests * feat: added customAsset field * fix: remove static in classes * fix: static class * fix: maximum payment * style: run spotless apply * fix: make MultiPayment class static --- .../crypto/configuration/Fee.java | 53 --- .../crypto/transactions/Deserializer.java | 183 ++++------ .../crypto/transactions/Serializer.java | 147 +++----- .../crypto/transactions/Transaction.java | 318 ------------------ .../crypto/transactions/TransactionAsset.java | 15 +- .../builder/AbstractTransactionBuilder.java | 20 +- .../builder/DelegateRegistration.java | 21 -- .../builder/DelegateRegistrationBuilder.java | 29 ++ .../builder/DelegateResignation.java | 16 - .../builder/DelegateResignationBuilder.java | 24 ++ .../transactions/builder/HtlcClaim.java | 22 -- .../builder/HtlcClaimBuilder.java | 29 ++ .../crypto/transactions/builder/HtlcLock.java | 38 --- .../transactions/builder/HtlcLockBuilder.java | 46 +++ .../transactions/builder/HtlcRefund.java | 21 -- .../builder/HtlcRefundBuilder.java | 28 ++ .../crypto/transactions/builder/Ipfs.java | 21 -- .../transactions/builder/IpfsBuilder.java | 28 ++ .../transactions/builder/MultiPayment.java | 38 --- .../builder/MultiPaymentBuilder.java | 45 +++ .../builder/MultiSignatureRegistration.java | 50 --- .../MultiSignatureRegistrationBuilder.java | 57 ++++ .../builder/SecondSignatureRegistration.java | 24 -- .../SecondSignatureRegistrationBuilder.java | 31 ++ .../crypto/transactions/builder/Transfer.java | 34 -- .../transactions/builder/TransferBuilder.java | 43 +++ .../crypto/transactions/builder/Vote.java | 31 -- .../transactions/builder/VoteBuilder.java | 43 +++ .../deserializers/AbstractDeserializer.java | 19 -- .../deserializers/DelegateRegistration.java | 24 -- .../deserializers/DelegateResignation.java | 15 - .../transactions/deserializers/HtlcClaim.java | 27 -- .../transactions/deserializers/HtlcLock.java | 33 -- .../deserializers/HtlcRefund.java | 22 -- .../transactions/deserializers/Ipfs.java | 31 -- .../deserializers/MultiPayment.java | 29 -- .../MultiSignatureRegistration.java | 30 -- .../SecondSignatureRegistration.java | 19 -- .../transactions/deserializers/Transfer.java | 25 -- .../transactions/deserializers/Vote.java | 26 -- .../serializers/AbstractSerializer.java | 16 - .../serializers/DelegateRegistration.java | 18 - .../serializers/DelegateResignation.java | 13 - .../transactions/serializers/HtlcClaim.java | 17 - .../transactions/serializers/HtlcLock.java | 21 -- .../transactions/serializers/HtlcRefund.java | 16 - .../crypto/transactions/serializers/Ipfs.java | 16 - .../serializers/MultiPayment.java | 21 -- .../MultiSignatureRegistration.java | 30 -- .../SecondSignatureRegistration.java | 16 - .../transactions/serializers/Transfer.java | 18 - .../crypto/transactions/serializers/Vote.java | 26 -- .../types/DelegateRegistration.java | 51 +++ .../types/DelegateResignation.java | 31 ++ .../crypto/transactions/types/HtlcClaim.java | 54 +++ .../crypto/transactions/types/HtlcLock.java | 71 ++++ .../crypto/transactions/types/HtlcRefund.java | 47 +++ .../crypto/transactions/types/Ipfs.java | 54 +++ .../transactions/types/MultiPayment.java | 66 ++++ .../types/MultiSignatureRegistration.java | 38 +++ .../types/SecondSignatureRegistration.java | 50 +++ .../transactions/types/Transaction.java | 143 ++++++++ .../crypto/transactions/types/Transfer.java | 50 +++ .../crypto/transactions/types/Vote.java | 57 ++++ .../crypto/configuration/FeeTest.java | 26 -- .../crypto/transactions/FixtureLoader.java | 1 + .../DelegateRegistrationBuilderTest.java | 38 +++ .../builder/DelegateRegistrationTest.java | 60 ---- ...va => DelegateResignationBuilderTest.java} | 9 +- ...aimTest.java => HtlcClaimBuilderTest.java} | 8 +- ...LockTest.java => HtlcLockBuilderTest.java} | 12 +- ...ndTest.java => HtlcRefundBuilderTest.java} | 8 +- .../{IpfsTest.java => IpfsBuilderTest.java} | 10 +- .../builder/MultiPaymentBuilderTest.java | 42 +++ .../builder/MultiPaymentTest.java | 75 ----- ...MultiSignatureRegistrationBuilderTest.java | 18 + .../MultiSignatureRegistrationTest.java | 48 --- ...econdSignatureRegistrationBuilderTest.java | 22 ++ .../SecondSignatureRegistrationTest.java | 31 -- .../builder/TransferBuilderTest.java | 45 +++ .../transactions/builder/TransferTest.java | 69 ---- .../{VoteTest.java => VoteBuilderTest.java} | 48 +-- .../DelegateRegistrationTest.java | 112 ++---- .../DelegateResignationTest.java | 27 +- .../deserializers/HtlcClaimTest.java | 31 +- .../deserializers/HtlcLockTest.java | 106 +++++- .../deserializers/HtlcRefundTest.java | 30 +- .../transactions/deserializers/IpfsTest.java | 28 +- .../deserializers/MultiPaymentTest.java | 92 ++++- .../MultiSignatureRegistrationTest.java | 38 --- .../SecondSignatureRegistrationTest.java | 35 +- .../deserializers/TransferTest.java | 230 +++++-------- .../transactions/deserializers/VoteTest.java | 176 +++++----- .../serializers/DelegateRegistrationTest.java | 45 +-- .../serializers/DelegateResignationTest.java | 14 +- .../serializers/HtlcClaimTest.java | 16 +- .../serializers/HtlcLockTest.java | 38 ++- .../serializers/HtlcRefundTest.java | 18 +- .../transactions/serializers/IpfsTest.java | 16 +- .../serializers/MultiPaymentTest.java | 39 ++- .../MultiSignatureRegistrationTest.java | 26 -- .../SecondSignatureRegistrationTest.java | 15 +- .../serializers/TransferTest.java | 133 ++------ .../transactions/serializers/VoteTest.java | 65 ++-- .../delegate-registration-multiSign.json | 20 -- .../delegate-resignation-multiSign.json | 15 - .../v2-ecdsa/htlc-claim-multiSign.json | 21 -- .../v2-ecdsa/htlc-lock-multiSign.json | 25 -- ...htlc-lock-with-vendor-field-multiSign.json | 26 -- .../v2-ecdsa/htlc-refund-multiSign.json | 20 -- .../transactions/v2-ecdsa/ipfs-multiSign.json | 18 - .../v2-ecdsa/multi-payment-multiSign.json | 27 -- ...i-payment-with-vendor-field-multiSign.json | 28 -- .../v2-ecdsa/transfer-multiSign.json | 17 - .../transfer-with-vendor-field-multiSign.json | 18 - .../v2-ecdsa/unvote-multiSign.json | 20 -- .../transactions/v2-ecdsa/vote-multiSign.json | 20 -- 117 files changed, 2101 insertions(+), 2769 deletions(-) delete mode 100644 src/main/java/org/arkecosystem/crypto/configuration/Fee.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/Transaction.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistration.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationBuilder.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateResignation.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateResignationBuilder.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcClaim.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcClaimBuilder.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcLock.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcLockBuilder.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcRefund.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcRefundBuilder.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/Ipfs.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/IpfsBuilder.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/MultiPayment.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentBuilder.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistration.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationBuilder.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistration.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationBuilder.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/Transfer.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/TransferBuilder.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/Vote.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/builder/VoteBuilder.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/AbstractDeserializer.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/DelegateRegistration.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/DelegateResignation.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcClaim.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcLock.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcRefund.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/Ipfs.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/MultiPayment.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/MultiSignatureRegistration.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/SecondSignatureRegistration.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/Transfer.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/deserializers/Vote.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/AbstractSerializer.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/DelegateRegistration.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/DelegateResignation.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcClaim.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcLock.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcRefund.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/Ipfs.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/MultiPayment.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/MultiSignatureRegistration.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/SecondSignatureRegistration.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/Transfer.java delete mode 100644 src/main/java/org/arkecosystem/crypto/transactions/serializers/Vote.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/DelegateRegistration.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/DelegateResignation.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/HtlcClaim.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/HtlcLock.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/HtlcRefund.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/Ipfs.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/MultiPayment.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/MultiSignatureRegistration.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/SecondSignatureRegistration.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/Transaction.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/Transfer.java create mode 100644 src/main/java/org/arkecosystem/crypto/transactions/types/Vote.java delete mode 100644 src/test/java/org/arkecosystem/crypto/configuration/FeeTest.java create mode 100644 src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationBuilderTest.java delete mode 100644 src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationTest.java rename src/test/java/org/arkecosystem/crypto/transactions/builder/{DelegateResignationTest.java => DelegateResignationBuilderTest.java} (82%) rename src/test/java/org/arkecosystem/crypto/transactions/builder/{HtlcClaimTest.java => HtlcClaimBuilderTest.java} (88%) rename src/test/java/org/arkecosystem/crypto/transactions/builder/{HtlcLockTest.java => HtlcLockBuilderTest.java} (85%) rename src/test/java/org/arkecosystem/crypto/transactions/builder/{HtlcRefundTest.java => HtlcRefundBuilderTest.java} (87%) rename src/test/java/org/arkecosystem/crypto/transactions/builder/{IpfsTest.java => IpfsBuilderTest.java} (86%) create mode 100644 src/test/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentBuilderTest.java delete mode 100644 src/test/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentTest.java create mode 100644 src/test/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationBuilderTest.java delete mode 100644 src/test/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationTest.java create mode 100644 src/test/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationBuilderTest.java delete mode 100644 src/test/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationTest.java create mode 100644 src/test/java/org/arkecosystem/crypto/transactions/builder/TransferBuilderTest.java delete mode 100644 src/test/java/org/arkecosystem/crypto/transactions/builder/TransferTest.java rename src/test/java/org/arkecosystem/crypto/transactions/builder/{VoteTest.java => VoteBuilderTest.java} (51%) delete mode 100644 src/test/java/org/arkecosystem/crypto/transactions/deserializers/MultiSignatureRegistrationTest.java delete mode 100644 src/test/java/org/arkecosystem/crypto/transactions/serializers/MultiSignatureRegistrationTest.java delete mode 100644 src/test/resources/transactions/v2-ecdsa/delegate-registration-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/delegate-resignation-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/htlc-claim-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/htlc-lock-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/htlc-lock-with-vendor-field-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/htlc-refund-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/ipfs-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/multi-payment-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/multi-payment-with-vendor-field-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/transfer-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/transfer-with-vendor-field-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/unvote-multiSign.json delete mode 100644 src/test/resources/transactions/v2-ecdsa/vote-multiSign.json diff --git a/src/main/java/org/arkecosystem/crypto/configuration/Fee.java b/src/main/java/org/arkecosystem/crypto/configuration/Fee.java deleted file mode 100644 index a7ce7720..00000000 --- a/src/main/java/org/arkecosystem/crypto/configuration/Fee.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.arkecosystem.crypto.configuration; - -import java.util.HashMap; -import java.util.Map; -import org.arkecosystem.crypto.enums.CoreTransactionTypes; -import org.arkecosystem.crypto.enums.Fees; -import org.arkecosystem.crypto.enums.TransactionTypeGroup; - -public class Fee { - private static Map> internalTransactionTypes = new HashMap<>(); - - static { - Map coreFees = new HashMap<>(); - - coreFees.put(CoreTransactionTypes.TRANSFER.getValue(), Fees.TRANSFER.getValue()); - coreFees.put( - CoreTransactionTypes.SECOND_SIGNATURE_REGISTRATION.getValue(), - Fees.SECOND_SIGNATURE_REGISTRATION.getValue()); - coreFees.put( - CoreTransactionTypes.DELEGATE_REGISTRATION.getValue(), - Fees.DELEGATE_REGISTRATION.getValue()); - coreFees.put(CoreTransactionTypes.VOTE.getValue(), Fees.VOTE.getValue()); - coreFees.put( - CoreTransactionTypes.MULTI_SIGNATURE_REGISTRATION.getValue(), - Fees.MULTI_SIGNATURE_REGISTRATION.getValue()); - coreFees.put(CoreTransactionTypes.IPFS.getValue(), Fees.IPFS.getValue()); - coreFees.put(CoreTransactionTypes.MULTI_PAYMENT.getValue(), Fees.MULTI_PAYMENT.getValue()); - coreFees.put( - CoreTransactionTypes.DELEGATE_RESIGNATION.getValue(), - Fees.DELEGATE_RESIGNATION.getValue()); - coreFees.put(CoreTransactionTypes.HTLC_LOCK.getValue(), Fees.HTLC_LOCK.getValue()); - coreFees.put(CoreTransactionTypes.HTLC_CLAIM.getValue(), Fees.HTLC_CLAIM.getValue()); - coreFees.put(CoreTransactionTypes.HTLC_REFUND.getValue(), Fees.HTLC_REFUND.getValue()); - - internalTransactionTypes.put(TransactionTypeGroup.CORE.getValue(), coreFees); - } - - public static long getFee(int transactionTypeGroup, int type) { - return internalTransactionTypes.get(transactionTypeGroup).get(type); - } - - public static long getCoreFee(int type) { - return internalTransactionTypes.get(TransactionTypeGroup.CORE.getValue()).get(type); - } - - public static void set(int transactionTypeGroup, Map transactionTypes) { - if (transactionTypeGroup < TransactionTypeGroup.RESERVED.getValue()) { - throw new IllegalArgumentException( - "Cannot add TransactionTypeGroup with value less then 1000"); - } - internalTransactionTypes.put(transactionTypeGroup, transactionTypes); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/Deserializer.java b/src/main/java/org/arkecosystem/crypto/transactions/Deserializer.java index da7280f0..cb678051 100644 --- a/src/main/java/org/arkecosystem/crypto/transactions/Deserializer.java +++ b/src/main/java/org/arkecosystem/crypto/transactions/Deserializer.java @@ -2,145 +2,110 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.util.HashMap; +import java.util.Map; import org.arkecosystem.crypto.encoding.Hex; import org.arkecosystem.crypto.enums.CoreTransactionTypes; -import org.arkecosystem.crypto.enums.TransactionTypeGroup; -import org.arkecosystem.crypto.identities.Address; -import org.arkecosystem.crypto.transactions.deserializers.*; +import org.arkecosystem.crypto.transactions.types.*; public class Deserializer { - private String serialized; private ByteBuffer buffer; private Transaction transaction; - public Transaction deserialize(String serialized) { - this.serialized = serialized; + private Map transactionsClasses = new HashMap<>(); + + public Deserializer(String serialized) { + this.transactionsClasses.put(CoreTransactionTypes.TRANSFER.getValue(), new Transfer()); + this.transactionsClasses.put( + CoreTransactionTypes.SECOND_SIGNATURE_REGISTRATION.getValue(), + new SecondSignatureRegistration()); + this.transactionsClasses.put( + CoreTransactionTypes.DELEGATE_REGISTRATION.getValue(), new DelegateRegistration()); + this.transactionsClasses.put(CoreTransactionTypes.VOTE.getValue(), new Vote()); + this.transactionsClasses.put( + CoreTransactionTypes.MULTI_SIGNATURE_REGISTRATION.getValue(), + new MultiSignatureRegistration()); + this.transactionsClasses.put(CoreTransactionTypes.IPFS.getValue(), new Ipfs()); + this.transactionsClasses.put( + CoreTransactionTypes.MULTI_PAYMENT.getValue(), new MultiPayment()); + this.transactionsClasses.put( + CoreTransactionTypes.DELEGATE_RESIGNATION.getValue(), new DelegateResignation()); + this.transactionsClasses.put(CoreTransactionTypes.HTLC_LOCK.getValue(), new HtlcLock()); + this.transactionsClasses.put(CoreTransactionTypes.HTLC_CLAIM.getValue(), new HtlcClaim()); + this.transactionsClasses.put(CoreTransactionTypes.HTLC_REFUND.getValue(), new HtlcRefund()); + this.buffer = ByteBuffer.wrap(Hex.decode(serialized)).slice(); this.buffer.order(ByteOrder.LITTLE_ENDIAN); + } + + public Transaction deserialize() { this.buffer.get(); - this.transaction = new Transaction(); + deserializeCommon(); + deserializeVendorField(); - int assetOffset = deserializeHeader(); - deserializeTypeSpecific(assetOffset); + this.transaction.deserialize(this.buffer); - deserializeVersionOne(); + deserializeSignature(); + + this.transaction.computeId(); return this.transaction; } - private int deserializeHeader() { - transaction.version = this.buffer.get(); - transaction.network = this.buffer.get(); - if (transaction.version == 1) { - transaction.type = CoreTransactionTypes.values()[this.buffer.get()].getValue(); - transaction.timestamp = this.buffer.getInt(); - } else { - transaction.typeGroup = TransactionTypeGroup.values()[this.buffer.getInt()].getValue(); - transaction.type = CoreTransactionTypes.values()[this.buffer.getShort()].getValue(); - transaction.nonce = this.buffer.getLong(); - } + private void deserializeCommon() { + int version = this.buffer.get(); + int network = this.buffer.get(); + int typeGroup = this.buffer.getInt(); + int type = this.buffer.getShort(); + long nonce = this.buffer.getLong(); + + this.transaction = this.transactionsClasses.get(type); + this.transaction.version = version; + this.transaction.network = network; + this.transaction.typeGroup = typeGroup; + this.transaction.type = type; + this.transaction.nonce = nonce; + byte[] senderPublicKey = new byte[33]; this.buffer.get(senderPublicKey); - transaction.senderPublicKey = Hex.encode(senderPublicKey); + this.transaction.senderPublicKey = Hex.encode(senderPublicKey); - transaction.fee = this.buffer.getLong(); + this.transaction.fee = this.buffer.getLong(); + } + private void deserializeVendorField() { int vendorFieldLength = this.buffer.get(); if (vendorFieldLength > 0) { - byte[] vendorFieldHex = new byte[vendorFieldLength]; - this.buffer.get(vendorFieldHex); - transaction.vendorFieldHex = Hex.encode(vendorFieldHex); - } - - if (transaction.version == 1) { - return (41 + 8 + 1) * 2 + vendorFieldLength * 2; - } else { - return 59 * 2 + vendorFieldLength * 2; + byte[] vendorField = new byte[vendorFieldLength]; + this.buffer.get(vendorField); + transaction.vendorField = new String(vendorField); } } - private void deserializeTypeSpecific(int assetOffset) { - CoreTransactionTypes transactionType = CoreTransactionTypes.values()[transaction.type]; - switch (transactionType) { - case TRANSFER: - new Transfer(this.serialized, this.buffer, this.transaction) - .deserialize(assetOffset); - break; - case SECOND_SIGNATURE_REGISTRATION: - new SecondSignatureRegistration(this.serialized, this.buffer, this.transaction) - .deserialize(assetOffset); - break; - case DELEGATE_REGISTRATION: - new DelegateRegistration(this.serialized, this.buffer, this.transaction) - .deserialize(assetOffset); - break; - case VOTE: - new Vote(this.serialized, this.buffer, this.transaction).deserialize(assetOffset); - break; - case MULTI_SIGNATURE_REGISTRATION: - new MultiSignatureRegistration(this.serialized, this.buffer, this.transaction) - .deserialize(assetOffset); - break; - case IPFS: - new Ipfs(this.serialized, this.buffer, this.transaction).deserialize(assetOffset); - break; - case MULTI_PAYMENT: - new MultiPayment(this.serialized, this.buffer, this.transaction) - .deserialize(assetOffset); - break; - case DELEGATE_RESIGNATION: - new DelegateResignation(this.serialized, this.buffer, this.transaction) - .deserialize(assetOffset); - break; - case HTLC_LOCK: - new HtlcLock(this.serialized, this.buffer, this.transaction) - .deserialize(assetOffset); - break; - case HTLC_CLAIM: - new HtlcClaim(this.serialized, this.buffer, this.transaction) - .deserialize(assetOffset); - break; - case HTLC_REFUND: - new HtlcRefund(this.serialized, this.buffer, this.transaction) - .deserialize(assetOffset); - break; - default: - throw new UnsupportedOperationException(); + private void deserializeSignature() { + if (buffer.remaining() != 0) { + int signatureLength = currentSignatureLength(); + byte[] signatureBuffer = new byte[signatureLength]; + this.buffer.get(signatureBuffer); + this.transaction.signature = Hex.encode(signatureBuffer); } - } - private void deserializeVersionOne() { - if (transaction.secondSignature != null) { - transaction.signSignature = transaction.secondSignature; - } - - if (transaction.type == CoreTransactionTypes.VOTE.getValue()) { - transaction.recipientId = - Address.fromPublicKey(transaction.senderPublicKey, transaction.network); - } - - if (transaction.type == CoreTransactionTypes.MULTI_SIGNATURE_REGISTRATION.getValue()) { - for (int i = 0; i < transaction.asset.multisignature.keysgroup.size(); i++) { - transaction.asset.multisignature.keysgroup.set( - i, "+" + transaction.asset.multisignature.keysgroup.get(i)); - } - } - - if (transaction.vendorFieldHex != null) { - transaction.vendorField = new String(Hex.decode(transaction.vendorFieldHex)); - } - - if (transaction.id == null) { - transaction.id = transaction.computeId(); + if (buffer.remaining() != 0) { + int signatureLength = currentSignatureLength(); + byte[] signatureBuffer = new byte[signatureLength]; + this.buffer.get(signatureBuffer); + this.transaction.secondSignature = Hex.encode(signatureBuffer); } + } - if (transaction.type == CoreTransactionTypes.SECOND_SIGNATURE_REGISTRATION.getValue() - || transaction.type - == CoreTransactionTypes.MULTI_SIGNATURE_REGISTRATION.getValue()) { - transaction.recipientId = - Address.fromPublicKey(transaction.senderPublicKey, transaction.network); - } + private int currentSignatureLength() { + int mark = this.buffer.position(); + this.buffer.position(mark + 1); + String length = String.valueOf(this.buffer.get()); + int signatureLength = Integer.parseInt(length) + 2; + this.buffer.position(mark); + return signatureLength; } } diff --git a/src/main/java/org/arkecosystem/crypto/transactions/Serializer.java b/src/main/java/org/arkecosystem/crypto/transactions/Serializer.java index 1c894c71..60273682 100644 --- a/src/main/java/org/arkecosystem/crypto/transactions/Serializer.java +++ b/src/main/java/org/arkecosystem/crypto/transactions/Serializer.java @@ -4,136 +4,93 @@ import java.nio.ByteOrder; import org.arkecosystem.crypto.configuration.Network; import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.enums.CoreTransactionTypes; -import org.arkecosystem.crypto.transactions.serializers.*; +import org.arkecosystem.crypto.transactions.types.Transaction; public class Serializer { - private ByteBuffer buffer; private Transaction transaction; - public byte[] serialize( - Transaction transaction, boolean skipSignature, boolean skipSecondSignature) { + public Serializer(Transaction transaction) { this.transaction = transaction; + } + + public static byte[] serialize(Transaction transaction) { + return new Serializer(transaction).serialize(false, false); + } + + public static byte[] serialize( + Transaction transaction, boolean skipSignature, boolean skipSecondSignature) { + return new Serializer(transaction).serialize(skipSignature, skipSecondSignature); + } - this.buffer = ByteBuffer.allocate(512); - this.buffer.order(ByteOrder.LITTLE_ENDIAN); + public byte[] serialize(boolean skipSignature, boolean skipSecondSignature) { + ByteBuffer buffer = ByteBuffer.allocate(512); + buffer.order(ByteOrder.LITTLE_ENDIAN); - serializeHeader(); - serializeVendorField(); + serializeCommon(buffer); + serializeVendorField(buffer); - serializeTypeSpecific(); + byte[] typeBuffer = this.transaction.serialize(); + buffer.put(typeBuffer); - serializeSignatures(skipSignature, skipSecondSignature); + serializeSignatures(buffer, skipSignature, skipSecondSignature); - byte[] result = new byte[this.buffer.position()]; - this.buffer.rewind(); - this.buffer.get(result); + byte[] result = new byte[buffer.position()]; + buffer.rewind(); + buffer.get(result); return result; } - public byte[] serialize(Transaction transaction) { - return this.serialize(transaction, false, false); - } - - private void serializeHeader() { - this.buffer.put((byte) 0xff); - + private void serializeCommon(ByteBuffer buffer) { + buffer.put((byte) 0xff); if (this.transaction.version > 0) { - this.buffer.put((byte) this.transaction.version); + buffer.put((byte) this.transaction.version); } else { - this.buffer.put((byte) 0x01); + buffer.put((byte) 0x01); } - if (this.transaction.network > 0) { - this.buffer.put((byte) this.transaction.network); + buffer.put((byte) this.transaction.network); } else { - this.buffer.put((byte) Network.get().version()); + buffer.put((byte) Network.get().version()); } - if (transaction.version == 1) { - this.buffer.put((byte) this.transaction.type); - this.buffer.putInt(this.transaction.timestamp); - } else { - this.buffer.putInt(this.transaction.typeGroup); - this.buffer.putShort((short) this.transaction.type); - this.buffer.putLong(this.transaction.nonce); - } + buffer.putInt(this.transaction.typeGroup); + buffer.putShort((short) this.transaction.type); + buffer.putLong(this.transaction.nonce); - this.buffer.put(Hex.decode(this.transaction.senderPublicKey)); - this.buffer.putLong(this.transaction.fee); + buffer.put(Hex.decode(this.transaction.senderPublicKey)); + buffer.putLong(this.transaction.fee); } - private void serializeVendorField() { - if (this.transaction.vendorField != null) { - int vendorFieldLength = this.transaction.vendorField.length(); - - this.buffer.put((byte) vendorFieldLength); - this.buffer.put(this.transaction.vendorField.getBytes()); - } else if (this.transaction.vendorFieldHex != null) { - int vendorFieldHexLength = this.transaction.vendorFieldHex.length(); - - this.buffer.put((byte) (vendorFieldHexLength / 2)); - this.buffer.put(Hex.decode(this.transaction.vendorFieldHex)); + private void serializeVendorField(ByteBuffer buffer) { + if (this.transaction.hasVendorField()) { + if (this.transaction.vendorField != null && !this.transaction.vendorField.equals("")) { + int vendorFieldLength = this.transaction.vendorField.length(); + buffer.put((byte) vendorFieldLength); + buffer.put(this.transaction.vendorField.getBytes()); + } else if (this.transaction.vendorFieldHex != null + && !this.transaction.vendorFieldHex.equals("")) { + int vendorFieldHexLength = this.transaction.vendorFieldHex.length(); + buffer.put((byte) (vendorFieldHexLength / 2)); + buffer.put(Hex.decode(this.transaction.vendorFieldHex)); + } else { + buffer.put((byte) 0x00); + } } else { - this.buffer.put((byte) 0x00); + buffer.put((byte) 0x00); } } - private void serializeTypeSpecific() { - CoreTransactionTypes transactionType = CoreTransactionTypes.values()[transaction.type]; - switch (transactionType) { - case TRANSFER: - new Transfer(this.buffer, this.transaction).serialize(); - break; - case SECOND_SIGNATURE_REGISTRATION: - new SecondSignatureRegistration(this.buffer, this.transaction).serialize(); - break; - case DELEGATE_REGISTRATION: - new DelegateRegistration(this.buffer, this.transaction).serialize(); - break; - case VOTE: - new Vote(this.buffer, this.transaction).serialize(); - break; - case MULTI_SIGNATURE_REGISTRATION: - new MultiSignatureRegistration(this.buffer, this.transaction).serialize(); - break; - case IPFS: - new Ipfs(this.buffer, this.transaction).serialize(); - break; - case MULTI_PAYMENT: - new MultiPayment(this.buffer, this.transaction).serialize(); - break; - case DELEGATE_RESIGNATION: - new DelegateResignation(this.buffer, this.transaction).serialize(); - break; - case HTLC_LOCK: - new HtlcLock(this.buffer, this.transaction).serialize(); - break; - case HTLC_CLAIM: - new HtlcClaim(this.buffer, this.transaction).serialize(); - break; - case HTLC_REFUND: - new HtlcRefund(this.buffer, this.transaction).serialize(); - break; - default: - throw new UnsupportedOperationException(); - } - } + private void serializeSignatures( + ByteBuffer buffer, boolean skipSignature, boolean skipSecondSignature) { - private void serializeSignatures(boolean skipSignature, boolean skipSecondSignature) { - if (!skipSignature) { + if (!skipSignature && this.transaction.signature != null) { buffer.put(Hex.decode(this.transaction.signature)); } if (!skipSecondSignature && this.transaction.secondSignature != null) { buffer.put(Hex.decode(this.transaction.secondSignature)); } - - if (this.transaction.signatures != null) { - this.buffer.put((byte) 0xff); - buffer.put(Hex.decode(String.join("", this.transaction.signatures))); - } } } diff --git a/src/main/java/org/arkecosystem/crypto/transactions/Transaction.java b/src/main/java/org/arkecosystem/crypto/transactions/Transaction.java deleted file mode 100644 index 589648ca..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/Transaction.java +++ /dev/null @@ -1,318 +0,0 @@ -package org.arkecosystem.crypto.transactions; - -import com.google.gson.*; -import java.lang.reflect.Type; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import org.arkecosystem.crypto.encoding.Base58; -import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.enums.CoreTransactionTypes; -import org.arkecosystem.crypto.identities.PrivateKey; -import org.bitcoinj.core.ECKey; -import org.bitcoinj.core.Sha256Hash; -import org.bitcoinj.core.SignatureDecodeException; - -public class Transaction { - public int expiration; - public int network; - public int timestamp; - public int type; - public int version; - public List signatures; - public long amount = 0L; - public long fee = 0L; - public TransactionAsset asset = new TransactionAsset(); - public String id; - public String recipientId; - public String secondSignature; - public String senderPublicKey; - public String signature; - public String signSignature; - public String vendorField; - - public String vendorFieldHex; - public long nonce; - public int typeGroup; - - public static Transaction deserialize(String serialized) { - return new Deserializer().deserialize(serialized); - } - - public String computeId() { - return Hex.encode(Sha256Hash.hash(toBytes(false, false))); - } - - public Transaction sign(String passphrase) { - ECKey privateKey = PrivateKey.fromPassphrase(passphrase); - - this.senderPublicKey = privateKey.getPublicKeyAsHex(); - this.signature = - Hex.encode(privateKey.sign(Sha256Hash.of(toBytes(true, true))).encodeToDER()); - - return this; - } - - public Transaction secondSign(String passphrase) { - ECKey privateKey = PrivateKey.fromPassphrase(passphrase); - - this.signSignature = - Hex.encode(privateKey.sign(Sha256Hash.of(toBytes(false, true))).encodeToDER()); - - return this; - } - - public boolean verify() { - ECKey keys = ECKey.fromPublicOnly(Hex.decode(this.senderPublicKey)); - - byte[] signature = Hex.decode(this.signature); - byte[] bytes = this.toBytes(true, true); - - try { - return ECKey.verify(Sha256Hash.hash(bytes), signature, keys.getPubKey()); - } catch (SignatureDecodeException e) { - return false; - } - } - - public boolean secondVerify(String secondPublicKey) { - ECKey keys = ECKey.fromPublicOnly(Hex.decode(secondPublicKey)); - - byte[] signature = Hex.decode(this.signSignature); - byte[] bytes = toBytes(false, true); - - try { - return ECKey.verify(Sha256Hash.hash(bytes), signature, keys.getPubKey()); - } catch (SignatureDecodeException e) { - return false; - } - } - - private byte[] toBytes(boolean skipSignature, boolean skipSecondSignature) { - if (this.version == 1) { - return this.toBytesV1(skipSignature, skipSecondSignature); - } else { - return new Serializer().serialize(this, skipSignature, skipSecondSignature); - } - } - - @Deprecated - public Transaction parseSignatures(String serialized, int startOffset) { - this.signature = serialized.substring(startOffset); - int multiSignatureOffset = 0; - - if (this.signature.length() == 0) { - this.signature = null; - } else { - int signatureLength = Integer.parseInt(this.signature.substring(2, 4), 16) + 2; - this.signature = serialized.substring(startOffset, startOffset + signatureLength * 2); - multiSignatureOffset += signatureLength * 2; - this.secondSignature = serialized.substring(startOffset + signatureLength * 2); - - if (this.secondSignature.length() == 0) { - this.secondSignature = null; - } else { - if ("ff".equals(this.secondSignature.substring(0, 2))) { - this.secondSignature = null; - } else { - int secondSignatureLength = - Integer.parseInt(this.secondSignature.substring(2, 4), 16) + 2; - this.secondSignature = - this.secondSignature.substring(0, secondSignatureLength * 2); - multiSignatureOffset += secondSignatureLength * 2; - } - } - - String signatures = serialized.substring(startOffset + multiSignatureOffset); - if (signatures.length() == 0) { - return this; - } - - if (!signatures.substring(0, 2).equals("ff")) { - return this; - } - - signatures = signatures.substring(2); - this.signatures = new ArrayList<>(); - - boolean moreSignatures = true; - while (moreSignatures) { - int mLength = Integer.parseInt(signatures.substring(2, 4), 16) + 2; - - if (mLength > 0) { - this.signatures.add(signatures.substring(0, mLength * 2)); - } else { - moreSignatures = false; - } - - signatures = signatures.substring(mLength * 2); - - if (signatures.length() == 0) { - break; - } - } - } - - return this; - } - - private byte[] toBytesV1(boolean skipSignature, boolean skipSecondSignature) { - ByteBuffer buffer = ByteBuffer.allocate(1000); - buffer.order(ByteOrder.LITTLE_ENDIAN); - - buffer.put((byte) type); - buffer.putInt(timestamp); - buffer.put(Hex.decode(this.senderPublicKey)); - - boolean skipRecipientId = - this.type == CoreTransactionTypes.SECOND_SIGNATURE_REGISTRATION.getValue() - || this.type - == CoreTransactionTypes.MULTI_SIGNATURE_REGISTRATION.getValue(); - if (recipientId != null && !recipientId.isEmpty() && !skipRecipientId) { - buffer.put(Base58.decodeChecked(this.recipientId)); - } else { - buffer.put(new byte[21]); - } - - if (vendorField != null && !recipientId.isEmpty()) { - byte[] vbytes = vendorField.getBytes(); - if (vbytes.length <= 255) { - buffer.put(vbytes); - if (vbytes.length < 64) { - buffer.put(new byte[64 - vbytes.length]); - } - } - } else { - buffer.put(new byte[64]); - } - - buffer.putLong(amount); - buffer.putLong(fee); - - if (this.type == CoreTransactionTypes.SECOND_SIGNATURE_REGISTRATION.getValue()) { - buffer.put(Hex.decode(this.asset.signature.publicKey)); - } - - if (this.type == CoreTransactionTypes.DELEGATE_REGISTRATION.getValue()) { - buffer.put(this.asset.delegate.username.getBytes()); - } - - if (this.type == CoreTransactionTypes.VOTE.getValue()) { - buffer.put(String.join("", this.asset.votes).getBytes()); - } - - if (this.type == CoreTransactionTypes.MULTI_SIGNATURE_REGISTRATION.getValue()) { - buffer.put(this.asset.multisignature.min); - buffer.put(this.asset.multisignature.lifetime); - buffer.put(String.join("", this.asset.multisignature.keysgroup).getBytes()); - } - - if (!skipSignature && signature != null) { - buffer.put(Hex.decode(this.signature)); - } - - if (!skipSecondSignature && signSignature != null) { - buffer.put(Hex.decode(this.signSignature)); - } - - byte[] result = new byte[buffer.position()]; - buffer.rewind(); - buffer.get(result); - return result; - } - - public String serialize() { - return Hex.encode(new Serializer().serialize(this)); - } - - public String toJson() { - GsonBuilder gsonBuilder = new GsonBuilder(); - return gsonBuilder.create().toJson(this.toHashMap()); - } - - public HashMap toHashMap() { - HashMap map = new HashMap(); - map.put("network", this.network); - map.put("id", this.id); - map.put("amount", String.valueOf(this.amount)); - map.put("fee", String.valueOf(this.fee)); - map.put("recipientId", this.recipientId); - map.put("signature", this.signature); - map.put("senderPublicKey", this.senderPublicKey); - map.put("type", this.type); - map.put("version", this.version); - if (this.version == 1) { - map.put("timestamp", this.timestamp); - } else { - map.put("nonce", String.valueOf(this.nonce)); - map.put("typeGroup", this.typeGroup); - } - - if (this.vendorField != null && !this.vendorField.isEmpty()) { - map.put("vendorField", this.vendorField); - } - - if (this.signSignature != null && !this.signSignature.isEmpty()) { - map.put("signSignature", this.signSignature); - } - - if (this.expiration > 0) { - map.put("expiration", this.expiration); - } - - HashMap asset = new HashMap<>(); - if (this.type == CoreTransactionTypes.SECOND_SIGNATURE_REGISTRATION.getValue()) { - HashMap publicKey = new HashMap<>(); - publicKey.put("publicKey", this.asset.signature.publicKey); - asset.put("signature", publicKey); - } else if (this.type == CoreTransactionTypes.VOTE.getValue()) { - asset.put("votes", this.asset.votes); - } else if (this.type == CoreTransactionTypes.DELEGATE_REGISTRATION.getValue()) { - HashMap delegate = new HashMap<>(); - delegate.put("username", this.asset.delegate.username); - asset.put("delegate", delegate); - } else if (this.type == CoreTransactionTypes.MULTI_SIGNATURE_REGISTRATION.getValue()) { - HashMap multisignature = new HashMap<>(); - multisignature.put("min", this.asset.multisignature.min); - multisignature.put("lifetime", this.asset.multisignature.lifetime); - multisignature.put("keysgroup", this.asset.multisignature.keysgroup); - asset.put("multisignature", multisignature); - } else if (this.type == CoreTransactionTypes.IPFS.getValue()) { - asset.put("ipfs", this.asset.ipfs); - } else if (this.type == CoreTransactionTypes.MULTI_PAYMENT.getValue()) { - ArrayList> payments = new ArrayList<>(); - for (TransactionAsset.Payment current : this.asset.multiPayment.payments) { - HashMap payment = new HashMap<>(); - payment.put("amount", String.valueOf(current.amount)); - payment.put("recipientId", current.recipientId); - payments.add(payment); - } - asset.put("payments", payments); - } - - if (!asset.isEmpty()) { - map.put("asset", asset); - } - return map; - } - - private static class TransactionTypeDeserializer - implements JsonDeserializer { - @Override - public CoreTransactionTypes deserialize( - JsonElement json, Type typeOfT, JsonDeserializationContext context) - throws JsonParseException { - return CoreTransactionTypes.values()[json.getAsInt()]; - } - } - - private static class TransactionTypeSerializer implements JsonSerializer { - @Override - public JsonElement serialize( - CoreTransactionTypes src, Type typeOfSrc, JsonSerializationContext context) { - return new JsonPrimitive(src.getValue()); - } - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/TransactionAsset.java b/src/main/java/org/arkecosystem/crypto/transactions/TransactionAsset.java index 7952a6a1..c3eb362c 100644 --- a/src/main/java/org/arkecosystem/crypto/transactions/TransactionAsset.java +++ b/src/main/java/org/arkecosystem/crypto/transactions/TransactionAsset.java @@ -13,22 +13,23 @@ public class TransactionAsset { public HtlcLockAsset htlcLockAsset = new HtlcLockAsset(); public HtlcClaimAsset htlcClaimAsset = new HtlcClaimAsset(); public HtlcRefundAsset htlcRefundAsset = new HtlcRefundAsset(); + public HashMap customAsset = new HashMap<>(); - public class Signature { + public static class Signature { public String publicKey; } - public class Delegate { + public static class Delegate { public String username; } - public class MultiSignature { + public static class MultiSignature { public byte min; public byte lifetime; public List keysgroup = new ArrayList<>(); } - public class MultiPayment { + public static class MultiPayment { public List payments = new ArrayList<>(); } @@ -42,7 +43,7 @@ public Payment(long amount, String recipientId) { } } - public class HtlcLockAsset { + public static class HtlcLockAsset { public String secretHash; public Expiration expiration; } @@ -57,12 +58,12 @@ public Expiration(HtlcLockExpirationType type, int value) { } } - public class HtlcClaimAsset { + public static class HtlcClaimAsset { public String lockTransactionId; public String unlockSecret; } - public class HtlcRefundAsset { + public static class HtlcRefundAsset { public String lockTransactionId; } } diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/AbstractTransactionBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/AbstractTransactionBuilder.java index 67958c0e..2812f535 100644 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/AbstractTransactionBuilder.java +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/AbstractTransactionBuilder.java @@ -1,25 +1,21 @@ package org.arkecosystem.crypto.transactions.builder; -import org.arkecosystem.crypto.configuration.Fee; import org.arkecosystem.crypto.configuration.Network; import org.arkecosystem.crypto.enums.CoreTransactionTypes; -import org.arkecosystem.crypto.enums.TransactionTypeGroup; -import org.arkecosystem.crypto.transactions.Transaction; -import org.arkecosystem.crypto.utils.Slot; +import org.arkecosystem.crypto.transactions.types.Transaction; public abstract class AbstractTransactionBuilder< TBuilder extends AbstractTransactionBuilder> { public Transaction transaction; public AbstractTransactionBuilder() { - this.transaction = new Transaction(); - this.transaction.type = this.getType(); - this.transaction.fee = Fee.getCoreFee(this.getType()); - this.transaction.timestamp = Slot.time(); + this.transaction = getTransactionInstance(); + this.transaction.type = this.transaction.getTransactionType(); this.transaction.version = 2; this.transaction.network = Network.get().version(); - this.transaction.typeGroup = TransactionTypeGroup.CORE.getValue(); + this.transaction.typeGroup = this.transaction.getTransactionTypeGroup(); this.transaction.nonce = 0; + this.transaction.amount = 0; } public TBuilder version(int version) { @@ -43,7 +39,7 @@ public TBuilder nonce(long nonce) { public TBuilder secondSign(String passphrase) { this.transaction.secondSign(passphrase); - this.transaction.id = this.transaction.computeId(); + this.transaction.id = this.transaction.getId(); return this.instance(); } @@ -70,12 +66,12 @@ public TBuilder sign(String passphrase) { "Version 2 MultiSignatureRegistration is not supported in java sdk"); } this.transaction.sign(passphrase); - this.transaction.id = this.transaction.computeId(); + this.transaction.id = this.transaction.getId(); return this.instance(); } - abstract int getType(); + public abstract Transaction getTransactionInstance(); abstract TBuilder instance(); } diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistration.java deleted file mode 100644 index f34caaa5..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistration.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import org.arkecosystem.crypto.enums.CoreTransactionTypes; - -public class DelegateRegistration extends AbstractTransactionBuilder { - public DelegateRegistration username(String username) { - this.transaction.asset.delegate.username = username; - - return this; - } - - @Override - public int getType() { - return CoreTransactionTypes.DELEGATE_REGISTRATION.getValue(); - } - - @Override - public DelegateRegistration instance() { - return this; - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationBuilder.java new file mode 100644 index 00000000..2dad6887 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationBuilder.java @@ -0,0 +1,29 @@ +package org.arkecosystem.crypto.transactions.builder; + +import org.arkecosystem.crypto.enums.Fees; +import org.arkecosystem.crypto.transactions.types.DelegateRegistration; +import org.arkecosystem.crypto.transactions.types.Transaction; + +public class DelegateRegistrationBuilder + extends AbstractTransactionBuilder { + public DelegateRegistrationBuilder() { + super(); + this.transaction.fee = Fees.DELEGATE_REGISTRATION.getValue(); + } + + public DelegateRegistrationBuilder username(String username) { + this.transaction.asset.delegate.username = username; + + return this; + } + + @Override + public Transaction getTransactionInstance() { + return new DelegateRegistration(); + } + + @Override + public DelegateRegistrationBuilder instance() { + return this; + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateResignation.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateResignation.java deleted file mode 100644 index a7cbe94e..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateResignation.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import org.arkecosystem.crypto.enums.CoreTransactionTypes; - -public class DelegateResignation extends AbstractTransactionBuilder { - - @Override - public int getType() { - return CoreTransactionTypes.DELEGATE_RESIGNATION.getValue(); - } - - @Override - public DelegateResignation instance() { - return this; - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateResignationBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateResignationBuilder.java new file mode 100644 index 00000000..16205090 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/DelegateResignationBuilder.java @@ -0,0 +1,24 @@ +package org.arkecosystem.crypto.transactions.builder; + +import org.arkecosystem.crypto.enums.Fees; +import org.arkecosystem.crypto.transactions.types.DelegateResignation; +import org.arkecosystem.crypto.transactions.types.Transaction; + +public class DelegateResignationBuilder + extends AbstractTransactionBuilder { + + public DelegateResignationBuilder() { + super(); + this.transaction.fee = Fees.DELEGATE_RESIGNATION.getValue(); + } + + @Override + public Transaction getTransactionInstance() { + return new DelegateResignation(); + } + + @Override + public DelegateResignationBuilder instance() { + return this; + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcClaim.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcClaim.java deleted file mode 100644 index 860a16bd..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcClaim.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import org.arkecosystem.crypto.enums.CoreTransactionTypes; - -public class HtlcClaim extends AbstractTransactionBuilder { - - public HtlcClaim htlcClaimAsset(String lockTransactionId, String unlockSecret) { - this.transaction.asset.htlcClaimAsset.lockTransactionId = lockTransactionId; - this.transaction.asset.htlcClaimAsset.unlockSecret = unlockSecret; - return this; - } - - @Override - public int getType() { - return CoreTransactionTypes.HTLC_CLAIM.getValue(); - } - - @Override - public HtlcClaim instance() { - return this; - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcClaimBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcClaimBuilder.java new file mode 100644 index 00000000..01047914 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcClaimBuilder.java @@ -0,0 +1,29 @@ +package org.arkecosystem.crypto.transactions.builder; + +import org.arkecosystem.crypto.enums.Fees; +import org.arkecosystem.crypto.transactions.types.HtlcClaim; +import org.arkecosystem.crypto.transactions.types.Transaction; + +public class HtlcClaimBuilder extends AbstractTransactionBuilder { + + public HtlcClaimBuilder() { + super(); + this.transaction.fee = Fees.HTLC_CLAIM.getValue(); + } + + public HtlcClaimBuilder htlcClaimAsset(String lockTransactionId, String unlockSecret) { + this.transaction.asset.htlcClaimAsset.lockTransactionId = lockTransactionId; + this.transaction.asset.htlcClaimAsset.unlockSecret = unlockSecret; + return this; + } + + @Override + public Transaction getTransactionInstance() { + return new HtlcClaim(); + } + + @Override + public HtlcClaimBuilder instance() { + return this; + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcLock.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcLock.java deleted file mode 100644 index ce27e118..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcLock.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import org.arkecosystem.crypto.enums.CoreTransactionTypes; -import org.arkecosystem.crypto.enums.HtlcLockExpirationType; -import org.arkecosystem.crypto.transactions.TransactionAsset; - -public class HtlcLock extends AbstractTransactionBuilder { - public HtlcLock recipientId(String recipientId) { - this.transaction.recipientId = recipientId; - return this; - } - - public HtlcLock secretHash(String secretHash) { - this.transaction.asset.htlcLockAsset.secretHash = secretHash; - return this; - } - - public HtlcLock expirationType(HtlcLockExpirationType expirationType, int expirationValue) { - this.transaction.asset.htlcLockAsset.expiration = - new TransactionAsset.Expiration(expirationType, expirationValue); - return this; - } - - public HtlcLock vendorField(String vendorField) { - this.transaction.vendorField = vendorField; - return this; - } - - @Override - public int getType() { - return CoreTransactionTypes.HTLC_LOCK.getValue(); - } - - @Override - public HtlcLock instance() { - return this; - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcLockBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcLockBuilder.java new file mode 100644 index 00000000..99620356 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcLockBuilder.java @@ -0,0 +1,46 @@ +package org.arkecosystem.crypto.transactions.builder; + +import org.arkecosystem.crypto.enums.Fees; +import org.arkecosystem.crypto.enums.HtlcLockExpirationType; +import org.arkecosystem.crypto.transactions.TransactionAsset; +import org.arkecosystem.crypto.transactions.types.HtlcLock; +import org.arkecosystem.crypto.transactions.types.Transaction; + +public class HtlcLockBuilder extends AbstractTransactionBuilder { + public HtlcLockBuilder() { + super(); + this.transaction.fee = Fees.HTLC_LOCK.getValue(); + } + + public HtlcLockBuilder recipientId(String recipientId) { + this.transaction.recipientId = recipientId; + return this; + } + + public HtlcLockBuilder secretHash(String secretHash) { + this.transaction.asset.htlcLockAsset.secretHash = secretHash; + return this; + } + + public HtlcLockBuilder expirationType( + HtlcLockExpirationType expirationType, int expirationValue) { + this.transaction.asset.htlcLockAsset.expiration = + new TransactionAsset.Expiration(expirationType, expirationValue); + return this; + } + + public HtlcLockBuilder vendorField(String vendorField) { + this.transaction.vendorField = vendorField; + return this; + } + + @Override + public Transaction getTransactionInstance() { + return new HtlcLock(); + } + + @Override + public HtlcLockBuilder instance() { + return this; + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcRefund.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcRefund.java deleted file mode 100644 index e9ef1732..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcRefund.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import org.arkecosystem.crypto.enums.CoreTransactionTypes; - -public class HtlcRefund extends AbstractTransactionBuilder { - - public HtlcRefund htlcRefundAsset(String lockTransactionId) { - this.transaction.asset.htlcRefundAsset.lockTransactionId = lockTransactionId; - return this; - } - - @Override - public int getType() { - return CoreTransactionTypes.HTLC_REFUND.getValue(); - } - - @Override - public HtlcRefund instance() { - return this; - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcRefundBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcRefundBuilder.java new file mode 100644 index 00000000..a6634d49 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/HtlcRefundBuilder.java @@ -0,0 +1,28 @@ +package org.arkecosystem.crypto.transactions.builder; + +import org.arkecosystem.crypto.enums.Fees; +import org.arkecosystem.crypto.transactions.types.HtlcRefund; +import org.arkecosystem.crypto.transactions.types.Transaction; + +public class HtlcRefundBuilder extends AbstractTransactionBuilder { + + public HtlcRefundBuilder() { + super(); + this.transaction.fee = Fees.HTLC_REFUND.getValue(); + } + + public HtlcRefundBuilder htlcRefundAsset(String lockTransactionId) { + this.transaction.asset.htlcRefundAsset.lockTransactionId = lockTransactionId; + return this; + } + + @Override + public Transaction getTransactionInstance() { + return new HtlcRefund(); + } + + @Override + public HtlcRefundBuilder instance() { + return this; + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/Ipfs.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/Ipfs.java deleted file mode 100644 index aa210ff7..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/Ipfs.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import org.arkecosystem.crypto.enums.CoreTransactionTypes; - -public class Ipfs extends AbstractTransactionBuilder { - - public AbstractTransactionBuilder ipfsAsset(String ipfsId) { - this.transaction.asset.ipfs = ipfsId; - return this; - } - - @Override - public int getType() { - return CoreTransactionTypes.IPFS.getValue(); - } - - @Override - public Ipfs instance() { - return this; - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/IpfsBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/IpfsBuilder.java new file mode 100644 index 00000000..06d8f900 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/IpfsBuilder.java @@ -0,0 +1,28 @@ +package org.arkecosystem.crypto.transactions.builder; + +import org.arkecosystem.crypto.enums.Fees; +import org.arkecosystem.crypto.transactions.types.Ipfs; +import org.arkecosystem.crypto.transactions.types.Transaction; + +public class IpfsBuilder extends AbstractTransactionBuilder { + + public IpfsBuilder() { + super(); + this.transaction.fee = Fees.IPFS.getValue(); + } + + public IpfsBuilder ipfsAsset(String ipfsAsset) { + this.transaction.asset.ipfs = ipfsAsset; + return this; + } + + @Override + public Transaction getTransactionInstance() { + return new Ipfs(); + } + + @Override + public IpfsBuilder instance() { + return this; + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiPayment.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiPayment.java deleted file mode 100644 index aa42f325..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiPayment.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import org.arkecosystem.crypto.enums.CoreTransactionTypes; -import org.arkecosystem.crypto.transactions.TransactionAsset; - -public class MultiPayment extends AbstractTransactionBuilder { - - public MultiPayment addPayment(String recipientId, long amount) { - if (this.transaction.asset.multiPayment.payments.size() >= 2258) { - throw new MaximumPaymentCountExceededError(); - } - this.transaction.asset.multiPayment.payments.add( - new TransactionAsset.Payment(amount, recipientId)); - return this; - } - - public MultiPayment vendorField(String vendorField) { - this.transaction.vendorField = vendorField; - - return this; - } - - @Override - public int getType() { - return CoreTransactionTypes.MULTI_PAYMENT.getValue(); - } - - @Override - public MultiPayment instance() { - return this; - } -} - -class MaximumPaymentCountExceededError extends RuntimeException { - MaximumPaymentCountExceededError() { - super("Expected a maximum of 2258 payments"); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentBuilder.java new file mode 100644 index 00000000..61f56d59 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentBuilder.java @@ -0,0 +1,45 @@ +package org.arkecosystem.crypto.transactions.builder; + +import org.arkecosystem.crypto.enums.Fees; +import org.arkecosystem.crypto.transactions.TransactionAsset; +import org.arkecosystem.crypto.transactions.types.MultiPayment; +import org.arkecosystem.crypto.transactions.types.Transaction; + +public class MultiPaymentBuilder extends AbstractTransactionBuilder { + + public MultiPaymentBuilder() { + super(); + this.transaction.fee = Fees.MULTI_PAYMENT.getValue(); + } + + public MultiPaymentBuilder addPayment(String recipientId, long amount) { + if (this.transaction.asset.multiPayment.payments.size() >= 64) { + throw new MaximumPaymentCountExceededError(); + } + this.transaction.asset.multiPayment.payments.add( + new TransactionAsset.Payment(amount, recipientId)); + return this; + } + + public MultiPaymentBuilder vendorField(String vendorField) { + this.transaction.vendorField = vendorField; + + return this; + } + + @Override + public Transaction getTransactionInstance() { + return new MultiPayment(); + } + + @Override + public MultiPaymentBuilder instance() { + return this; + } +} + +class MaximumPaymentCountExceededError extends RuntimeException { + MaximumPaymentCountExceededError() { + super("Expected a maximum of 64 payments"); + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistration.java deleted file mode 100644 index 7bfc61ca..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistration.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import java.util.List; -import org.arkecosystem.crypto.enums.CoreTransactionTypes; - -public class MultiSignatureRegistration - extends AbstractTransactionBuilder { - public MultiSignatureRegistration() { - super(); - this.transaction.version = 1; - } - - public MultiSignatureRegistration min(int min) { - return this.min((byte) min); - } - - public MultiSignatureRegistration min(byte min) { - this.transaction.asset.multisignature.min = min; - - return this; - } - - public MultiSignatureRegistration lifetime(int lifetime) { - return this.lifetime((byte) lifetime); - } - - public MultiSignatureRegistration lifetime(byte lifetime) { - this.transaction.asset.multisignature.lifetime = lifetime; - - return this; - } - - public MultiSignatureRegistration keysgroup(List keysgroup) { - this.transaction.asset.multisignature.keysgroup = keysgroup; - - this.transaction.fee = (keysgroup.size() + 1) * this.transaction.fee; - - return this; - } - - @Override - public int getType() { - return CoreTransactionTypes.MULTI_SIGNATURE_REGISTRATION.getValue(); - } - - @Override - public MultiSignatureRegistration instance() { - return this; - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationBuilder.java new file mode 100644 index 00000000..60c340eb --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationBuilder.java @@ -0,0 +1,57 @@ +package org.arkecosystem.crypto.transactions.builder; + +import java.util.List; +import org.arkecosystem.crypto.enums.Fees; +import org.arkecosystem.crypto.transactions.types.MultiSignatureRegistration; +import org.arkecosystem.crypto.transactions.types.Transaction; + +public class MultiSignatureRegistrationBuilder + extends AbstractTransactionBuilder { + public MultiSignatureRegistrationBuilder() { + super(); + this.transaction.version = 1; + this.transaction.fee = Fees.MULTI_SIGNATURE_REGISTRATION.getValue(); + } + + @Override + public Transaction getTransactionInstance() { + return new MultiSignatureRegistration(); + } + + @Deprecated + public MultiSignatureRegistrationBuilder min(int min) { + return this.min((byte) min); + } + + @Deprecated + public MultiSignatureRegistrationBuilder min(byte min) { + this.transaction.asset.multisignature.min = min; + + return this; + } + + @Deprecated + public MultiSignatureRegistrationBuilder lifetime(int lifetime) { + return this.lifetime((byte) lifetime); + } + + @Deprecated + public MultiSignatureRegistrationBuilder lifetime(byte lifetime) { + this.transaction.asset.multisignature.lifetime = lifetime; + return this; + } + + @Deprecated + public MultiSignatureRegistrationBuilder keysgroup(List keysgroup) { + this.transaction.asset.multisignature.keysgroup = keysgroup; + + this.transaction.fee = (keysgroup.size() + 1) * this.transaction.fee; + + return this; + } + + @Override + public MultiSignatureRegistrationBuilder instance() { + return this; + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistration.java deleted file mode 100644 index 0c0b4777..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistration.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import org.arkecosystem.crypto.enums.CoreTransactionTypes; -import org.arkecosystem.crypto.identities.PublicKey; - -public class SecondSignatureRegistration - extends AbstractTransactionBuilder { - - public SecondSignatureRegistration signature(String signature) { - this.transaction.asset.signature.publicKey = PublicKey.fromPassphrase(signature); - - return this; - } - - @Override - public int getType() { - return CoreTransactionTypes.SECOND_SIGNATURE_REGISTRATION.getValue(); - } - - @Override - public SecondSignatureRegistration instance() { - return this; - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationBuilder.java new file mode 100644 index 00000000..623535d6 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationBuilder.java @@ -0,0 +1,31 @@ +package org.arkecosystem.crypto.transactions.builder; + +import org.arkecosystem.crypto.enums.Fees; +import org.arkecosystem.crypto.identities.PublicKey; +import org.arkecosystem.crypto.transactions.types.SecondSignatureRegistration; +import org.arkecosystem.crypto.transactions.types.Transaction; + +public class SecondSignatureRegistrationBuilder + extends AbstractTransactionBuilder { + + public SecondSignatureRegistrationBuilder() { + super(); + this.transaction.fee = Fees.SECOND_SIGNATURE_REGISTRATION.getValue(); + } + + public SecondSignatureRegistrationBuilder signature(String signature) { + this.transaction.asset.signature.publicKey = PublicKey.fromPassphrase(signature); + + return this; + } + + @Override + public Transaction getTransactionInstance() { + return new SecondSignatureRegistration(); + } + + @Override + public SecondSignatureRegistrationBuilder instance() { + return this; + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/Transfer.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/Transfer.java deleted file mode 100644 index 5318b864..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/Transfer.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import org.arkecosystem.crypto.enums.CoreTransactionTypes; - -public class Transfer extends AbstractTransactionBuilder { - - public Transfer recipient(String recipientId) { - this.transaction.recipientId = recipientId; - - return this; - } - - public Transfer amount(long amount) { - this.transaction.amount = amount; - - return this; - } - - public Transfer vendorField(String vendorField) { - this.transaction.vendorField = vendorField; - - return this; - } - - @Override - public int getType() { - return CoreTransactionTypes.TRANSFER.getValue(); - } - - @Override - public Transfer instance() { - return this; - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/TransferBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/TransferBuilder.java new file mode 100644 index 00000000..83ce42bc --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/TransferBuilder.java @@ -0,0 +1,43 @@ +package org.arkecosystem.crypto.transactions.builder; + +import org.arkecosystem.crypto.enums.Fees; +import org.arkecosystem.crypto.transactions.types.Transaction; +import org.arkecosystem.crypto.transactions.types.Transfer; + +public class TransferBuilder extends AbstractTransactionBuilder { + + public TransferBuilder() { + super(); + this.transaction.fee = Fees.TRANSFER.getValue(); + } + + public TransferBuilder recipient(String recipientId) { + this.transaction.recipientId = recipientId; + return this; + } + + public TransferBuilder amount(long amount) { + this.transaction.amount = amount; + return this; + } + + public TransferBuilder expiration(int expiration) { + this.transaction.expiration = expiration; + return this; + } + + public TransferBuilder vendorField(String vendorField) { + this.transaction.vendorField = vendorField; + return this; + } + + @Override + public Transaction getTransactionInstance() { + return new Transfer(); + } + + @Override + public TransferBuilder instance() { + return this; + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/Vote.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/Vote.java deleted file mode 100644 index 7a8582ae..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/builder/Vote.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import java.util.List; -import org.arkecosystem.crypto.enums.CoreTransactionTypes; -import org.arkecosystem.crypto.identities.Address; - -public class Vote extends AbstractTransactionBuilder { - public Vote votes(List votes) { - this.transaction.asset.votes = votes; - - return this; - } - - public Vote sign(String passphrase) { - this.transaction.recipientId = Address.fromPassphrase(passphrase); - - super.sign(passphrase); - - return this; - } - - @Override - public int getType() { - return CoreTransactionTypes.VOTE.getValue(); - } - - @Override - public Vote instance() { - return this; - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/builder/VoteBuilder.java b/src/main/java/org/arkecosystem/crypto/transactions/builder/VoteBuilder.java new file mode 100644 index 00000000..d0209cf8 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/builder/VoteBuilder.java @@ -0,0 +1,43 @@ +package org.arkecosystem.crypto.transactions.builder; + +import java.util.List; +import org.arkecosystem.crypto.enums.Fees; +import org.arkecosystem.crypto.identities.Address; +import org.arkecosystem.crypto.transactions.types.Transaction; +import org.arkecosystem.crypto.transactions.types.Vote; + +public class VoteBuilder extends AbstractTransactionBuilder { + + public VoteBuilder() { + super(); + this.transaction.fee = Fees.VOTE.getValue(); + } + + public VoteBuilder addVotes(List votes) { + this.transaction.asset.votes = votes; + return this; + } + + public VoteBuilder addVote(String vote) { + this.transaction.asset.votes.add(vote); + return this; + } + + public VoteBuilder sign(String passphrase) { + this.transaction.recipientId = Address.fromPassphrase(passphrase); + + super.sign(passphrase); + + return this; + } + + @Override + public Transaction getTransactionInstance() { + return new Vote(); + } + + @Override + public VoteBuilder instance() { + return this; + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/AbstractDeserializer.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/AbstractDeserializer.java deleted file mode 100644 index e2818983..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/AbstractDeserializer.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.transactions.Transaction; - -public abstract class AbstractDeserializer { - - protected String serialized; - protected ByteBuffer buffer; - protected Transaction transaction; - - public AbstractDeserializer(String serialized, ByteBuffer buffer, Transaction transaction) { - this.serialized = serialized; - this.buffer = buffer; - this.transaction = transaction; - } - - public abstract void deserialize(int assetOffset); -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/DelegateRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/DelegateRegistration.java deleted file mode 100644 index bbf04c44..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/DelegateRegistration.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.transactions.Transaction; - -public class DelegateRegistration extends AbstractDeserializer { - public DelegateRegistration(String serialized, ByteBuffer buffer, Transaction transaction) { - super(serialized, buffer, transaction); - } - - @Override - public void deserialize(int assetOffset) { - this.buffer.position(assetOffset / 2); - - int usernameLength = this.buffer.get() & 0xff; - - byte[] username = new byte[usernameLength]; - this.buffer.get(username); - - transaction.asset.delegate.username = new String(username); - - this.transaction.parseSignatures(this.serialized, assetOffset + (usernameLength + 1) * 2); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/DelegateResignation.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/DelegateResignation.java deleted file mode 100644 index 943e011d..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/DelegateResignation.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.transactions.Transaction; - -public class DelegateResignation extends AbstractDeserializer { - public DelegateResignation(String serialized, ByteBuffer buffer, Transaction transaction) { - super(serialized, buffer, transaction); - } - - @Override - public void deserialize(int assetOffset) { - this.transaction.parseSignatures(this.serialized, assetOffset); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcClaim.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcClaim.java deleted file mode 100644 index 2446091b..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcClaim.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.transactions.Transaction; - -public class HtlcClaim extends AbstractDeserializer { - public HtlcClaim(String serialized, ByteBuffer buffer, Transaction transaction) { - super(serialized, buffer, transaction); - } - - @Override - public void deserialize(int assetOffset) { - this.buffer.position(assetOffset / 2); - - byte[] lockTransactionIdBuf = new byte[32]; - this.buffer.get(lockTransactionIdBuf); - - byte[] unlockSecret = new byte[32]; - this.buffer.get(unlockSecret); - - this.transaction.asset.htlcClaimAsset.lockTransactionId = Hex.encode(lockTransactionIdBuf); - this.transaction.asset.htlcClaimAsset.unlockSecret = Hex.encode(unlockSecret); - - this.transaction.parseSignatures(this.serialized, assetOffset + 64 + 64); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcLock.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcLock.java deleted file mode 100644 index 3b96d771..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcLock.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Base58; -import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.enums.HtlcLockExpirationType; -import org.arkecosystem.crypto.transactions.Transaction; -import org.arkecosystem.crypto.transactions.TransactionAsset; - -public class HtlcLock extends AbstractDeserializer { - public HtlcLock(String serialized, ByteBuffer buffer, Transaction transaction) { - super(serialized, buffer, transaction); - } - - @Override - public void deserialize(int assetOffset) { - this.buffer.position(assetOffset / 2); - - this.transaction.amount = this.buffer.getLong(); - byte[] secretHash = new byte[32]; - this.buffer.get(secretHash); - this.transaction.asset.htlcLockAsset.secretHash = Hex.encode(secretHash); - this.transaction.asset.htlcLockAsset.expiration = - new TransactionAsset.Expiration( - HtlcLockExpirationType.values()[this.buffer.get() - 1], - this.buffer.getInt()); - byte[] recipientId = new byte[21]; - this.buffer.get(recipientId); - this.transaction.recipientId = Base58.encodeChecked(recipientId); - - this.transaction.parseSignatures(this.serialized, assetOffset + (8 + 32 + 1 + 4 + 21) * 2); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcRefund.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcRefund.java deleted file mode 100644 index a141855a..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/HtlcRefund.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.transactions.Transaction; - -public class HtlcRefund extends AbstractDeserializer { - public HtlcRefund(String serialized, ByteBuffer buffer, Transaction transaction) { - super(serialized, buffer, transaction); - } - - @Override - public void deserialize(int assetOffset) { - this.buffer.position(assetOffset / 2); - - byte[] buf = new byte[32]; - this.buffer.get(buf); - this.transaction.asset.htlcRefundAsset.lockTransactionId = Hex.encode(buf); - - this.transaction.parseSignatures(this.serialized, assetOffset + 64); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/Ipfs.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/Ipfs.java deleted file mode 100644 index 88e086e2..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/Ipfs.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Base58; -import org.arkecosystem.crypto.transactions.Transaction; - -public class Ipfs extends AbstractDeserializer { - public Ipfs(String serialized, ByteBuffer buffer, Transaction transaction) { - super(serialized, buffer, transaction); - } - - @Override - public void deserialize(int assetOffset) { - this.buffer.position(assetOffset / 2); - - byte hashFunction = this.buffer.get(); - byte ipfsHashLength = this.buffer.get(); - byte[] hashBuffer = new byte[ipfsHashLength]; - this.buffer.get(hashBuffer); - - byte[] ipfsBuffer = - ByteBuffer.allocate(ipfsHashLength + 2) - .put(hashFunction) - .put(ipfsHashLength) - .put(hashBuffer) - .array(); - this.transaction.asset.ipfs = Base58.encode(ipfsBuffer); - - this.transaction.parseSignatures(this.serialized, assetOffset + (ipfsHashLength + 2) * 2); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/MultiPayment.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/MultiPayment.java deleted file mode 100644 index e8980112..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/MultiPayment.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Base58; -import org.arkecosystem.crypto.transactions.Transaction; -import org.arkecosystem.crypto.transactions.TransactionAsset; - -public class MultiPayment extends AbstractDeserializer { - public MultiPayment(String serialized, ByteBuffer buffer, Transaction transaction) { - super(serialized, buffer, transaction); - } - - @Override - public void deserialize(int assetOffset) { - this.buffer.position(assetOffset / 2); - - int paymentLength = this.buffer.getShort() & 0xff; - for (int i = 0; i < paymentLength; i++) { - byte[] recipientId = new byte[21]; - long amount = this.buffer.getLong(); - this.buffer.get(recipientId); - this.transaction.asset.multiPayment.payments.add( - new TransactionAsset.Payment(amount, Base58.encodeChecked(recipientId))); - } - - this.transaction.parseSignatures( - this.serialized, assetOffset + ((2 + paymentLength * 8 + paymentLength * 21) * 2)); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/MultiSignatureRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/MultiSignatureRegistration.java deleted file mode 100644 index fa112644..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/MultiSignatureRegistration.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.transactions.Transaction; - -public class MultiSignatureRegistration extends AbstractDeserializer { - public MultiSignatureRegistration( - String serialized, ByteBuffer buffer, Transaction transaction) { - super(serialized, buffer, transaction); - } - - @Override - public void deserialize(int assetOffset) { - this.buffer.position(assetOffset / 2); - - this.transaction.asset.multisignature.min = (byte) (this.buffer.get() & 0xff); - - int count = this.buffer.get() & 0xff; - this.transaction.asset.multisignature.lifetime = (byte) (this.buffer.get() & 0xff); - - for (int i = 0; i < count; i++) { - String key = - this.serialized.substring( - assetOffset + 6 + i * 66, assetOffset + 6 + (i + 1) * 66); - this.transaction.asset.multisignature.keysgroup.add(key); - } - - this.transaction.parseSignatures(this.serialized, assetOffset + 6 + count * 66); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/SecondSignatureRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/SecondSignatureRegistration.java deleted file mode 100644 index 83bbb87b..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/SecondSignatureRegistration.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.transactions.Transaction; - -public class SecondSignatureRegistration extends AbstractDeserializer { - public SecondSignatureRegistration( - String serialized, ByteBuffer buffer, Transaction transaction) { - super(serialized, buffer, transaction); - } - - @Override - public void deserialize(int assetOffset) { - this.transaction.asset.signature.publicKey = - this.serialized.substring(assetOffset, assetOffset + 66); - - this.transaction.signature = this.serialized.substring(assetOffset + 66); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/Transfer.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/Transfer.java deleted file mode 100644 index 96b2bf47..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/Transfer.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Base58; -import org.arkecosystem.crypto.transactions.Transaction; - -public class Transfer extends AbstractDeserializer { - public Transfer(String serialized, ByteBuffer buffer, Transaction transaction) { - super(serialized, buffer, transaction); - } - - @Override - public void deserialize(int assetOffset) { - this.buffer.position(assetOffset / 2); - - this.transaction.amount = this.buffer.getLong(); - this.transaction.expiration = this.buffer.getInt(); - - byte[] recipientId = new byte[21]; - this.buffer.get(recipientId); - this.transaction.recipientId = Base58.encodeChecked(recipientId); - - this.transaction.parseSignatures(this.serialized, assetOffset + (8 + 4 + 21) * 2); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/Vote.java b/src/main/java/org/arkecosystem/crypto/transactions/deserializers/Vote.java deleted file mode 100644 index f20e098c..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/deserializers/Vote.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.transactions.Transaction; - -public class Vote extends AbstractDeserializer { - public Vote(String serialized, ByteBuffer buffer, Transaction transaction) { - super(serialized, buffer, transaction); - } - - @Override - public void deserialize(int assetOffset) { - this.buffer.position(assetOffset / 2); - int voteLength = this.buffer.get() & 0xff; - - for (int i = 0; i < voteLength; i++) { - String vote = - this.serialized.substring( - assetOffset + 2 + i * 2 * 34, assetOffset + 2 + (i + 1) * 2 * 34); - vote = (vote.startsWith("01") ? '+' : '-') + vote.substring(2); - transaction.asset.votes.add(vote); - } - - this.transaction.parseSignatures(this.serialized, assetOffset + 2 + voteLength * 34 * 2); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/AbstractSerializer.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/AbstractSerializer.java deleted file mode 100644 index 249a2990..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/AbstractSerializer.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.transactions.Transaction; - -public abstract class AbstractSerializer { - protected ByteBuffer buffer; - protected Transaction transaction; - - public AbstractSerializer(ByteBuffer buffer, Transaction transaction) { - this.buffer = buffer; - this.transaction = transaction; - } - - abstract void serialize(); -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/DelegateRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/DelegateRegistration.java deleted file mode 100644 index 5f8ad484..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/DelegateRegistration.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.transactions.Transaction; - -public class DelegateRegistration extends AbstractSerializer { - public DelegateRegistration(ByteBuffer buffer, Transaction transaction) { - super(buffer, transaction); - } - - @Override - public void serialize() { - byte[] delegateBytes = this.transaction.asset.delegate.username.getBytes(); - - this.buffer.put((byte) delegateBytes.length); - this.buffer.put(delegateBytes); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/DelegateResignation.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/DelegateResignation.java deleted file mode 100644 index 1798ad2e..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/DelegateResignation.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.transactions.Transaction; - -public class DelegateResignation extends AbstractSerializer { - public DelegateResignation(ByteBuffer buffer, Transaction transaction) { - super(buffer, transaction); - } - - @Override - public void serialize() {} -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcClaim.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcClaim.java deleted file mode 100644 index 87315071..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcClaim.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.transactions.Transaction; - -public class HtlcClaim extends AbstractSerializer { - public HtlcClaim(ByteBuffer buffer, Transaction transaction) { - super(buffer, transaction); - } - - @Override - public void serialize() { - this.buffer.put(Hex.decode(this.transaction.asset.htlcClaimAsset.lockTransactionId)); - this.buffer.put(Hex.decode(this.transaction.asset.htlcClaimAsset.unlockSecret)); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcLock.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcLock.java deleted file mode 100644 index ba7f6a86..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcLock.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Base58; -import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.transactions.Transaction; - -public class HtlcLock extends AbstractSerializer { - public HtlcLock(ByteBuffer buffer, Transaction transaction) { - super(buffer, transaction); - } - - @Override - public void serialize() { - this.buffer.putLong(this.transaction.amount); - this.buffer.put(Hex.decode(this.transaction.asset.htlcLockAsset.secretHash)); - this.buffer.put((byte) this.transaction.asset.htlcLockAsset.expiration.type.getValue()); - this.buffer.putInt(this.transaction.asset.htlcLockAsset.expiration.value); - this.buffer.put(Base58.decodeChecked(this.transaction.recipientId)); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcRefund.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcRefund.java deleted file mode 100644 index a89d0edf..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/HtlcRefund.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.transactions.Transaction; - -public class HtlcRefund extends AbstractSerializer { - public HtlcRefund(ByteBuffer buffer, Transaction transaction) { - super(buffer, transaction); - } - - @Override - public void serialize() { - this.buffer.put(Hex.decode(this.transaction.asset.htlcRefundAsset.lockTransactionId)); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/Ipfs.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/Ipfs.java deleted file mode 100644 index e173ad8a..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/Ipfs.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Base58; -import org.arkecosystem.crypto.transactions.Transaction; - -public class Ipfs extends AbstractSerializer { - public Ipfs(ByteBuffer buffer, Transaction transaction) { - super(buffer, transaction); - } - - @Override - public void serialize() { - this.buffer.put(Base58.decode(this.transaction.asset.ipfs)); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/MultiPayment.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/MultiPayment.java deleted file mode 100644 index 42a5314c..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/MultiPayment.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.transactions.Transaction; -import org.arkecosystem.crypto.transactions.TransactionAsset; -import org.bitcoinj.core.Base58; - -public class MultiPayment extends AbstractSerializer { - public MultiPayment(ByteBuffer buffer, Transaction transaction) { - super(buffer, transaction); - } - - @Override - public void serialize() { - this.buffer.putShort((short) this.transaction.asset.multiPayment.payments.size()); - for (TransactionAsset.Payment current : this.transaction.asset.multiPayment.payments) { - this.buffer.putLong(current.amount); - this.buffer.put(Base58.decodeChecked(current.recipientId)); - } - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/MultiSignatureRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/MultiSignatureRegistration.java deleted file mode 100644 index ae49af7c..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/MultiSignatureRegistration.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.transactions.Transaction; -import org.arkecosystem.crypto.transactions.TransactionAsset; - -public class MultiSignatureRegistration extends AbstractSerializer { - public MultiSignatureRegistration(ByteBuffer buffer, Transaction transaction) { - super(buffer, transaction); - } - - @Override - public void serialize() { - TransactionAsset.MultiSignature multiSignature = this.transaction.asset.multisignature; - - for (int i = 0; i < multiSignature.keysgroup.size(); i++) { - String key = multiSignature.keysgroup.get(i); - - if (key.startsWith("+")) { - multiSignature.keysgroup.set(i, key.substring(1)); - } - } - - this.buffer.put(multiSignature.min); - this.buffer.put((byte) multiSignature.keysgroup.size()); - this.buffer.put(multiSignature.lifetime); - this.buffer.put(Hex.decode(String.join("", multiSignature.keysgroup))); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/SecondSignatureRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/SecondSignatureRegistration.java deleted file mode 100644 index 54657c6c..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/SecondSignatureRegistration.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.transactions.Transaction; - -public class SecondSignatureRegistration extends AbstractSerializer { - public SecondSignatureRegistration(ByteBuffer buffer, Transaction transaction) { - super(buffer, transaction); - } - - @Override - public void serialize() { - this.buffer.put(Hex.decode(this.transaction.asset.signature.publicKey)); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/Transfer.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/Transfer.java deleted file mode 100644 index 4a9d6f18..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/Transfer.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import org.arkecosystem.crypto.transactions.Transaction; -import org.bitcoinj.core.Base58; - -public class Transfer extends AbstractSerializer { - public Transfer(ByteBuffer buffer, Transaction transaction) { - super(buffer, transaction); - } - - @Override - public void serialize() { - this.buffer.putLong(this.transaction.amount); - this.buffer.putInt(this.transaction.expiration); - this.buffer.put(Base58.decodeChecked(this.transaction.recipientId)); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/serializers/Vote.java b/src/main/java/org/arkecosystem/crypto/transactions/serializers/Vote.java deleted file mode 100644 index f2bc334f..00000000 --- a/src/main/java/org/arkecosystem/crypto/transactions/serializers/Vote.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; -import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.transactions.Transaction; - -public class Vote extends AbstractSerializer { - public Vote(ByteBuffer buffer, Transaction transaction) { - super(buffer, transaction); - } - - @Override - public void serialize() { - List votes = new ArrayList<>(transaction.asset.votes); - - for (int i = 0; i < votes.size(); i++) { - votes.set( - i, (votes.get(i).startsWith("+") ? "01" : "00") + (votes.get(i).substring(1))); - } - this.buffer.put((byte) votes.size()); - - this.buffer.put(Hex.decode(String.join("", votes))); - } -} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/DelegateRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/types/DelegateRegistration.java new file mode 100644 index 00000000..13d9ae63 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/DelegateRegistration.java @@ -0,0 +1,51 @@ +package org.arkecosystem.crypto.transactions.types; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.HashMap; +import org.arkecosystem.crypto.enums.CoreTransactionTypes; +import org.arkecosystem.crypto.enums.TransactionTypeGroup; + +public class DelegateRegistration extends Transaction { + @Override + public int getTransactionType() { + return CoreTransactionTypes.DELEGATE_REGISTRATION.getValue(); + } + + @Override + public int getTransactionTypeGroup() { + return TransactionTypeGroup.CORE.getValue(); + } + + @Override + public HashMap assetToHashMap() { + HashMap asset = new HashMap<>(); + + HashMap delegate = new HashMap<>(); + delegate.put("username", this.asset.delegate.username); + asset.put("delegate", delegate); + + return asset; + } + + @Override + public byte[] serialize() { + byte[] delegateBytes = this.asset.delegate.username.getBytes(); + + ByteBuffer buffer = ByteBuffer.allocate(1 + delegateBytes.length); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.put((byte) delegateBytes.length); + buffer.put(delegateBytes); + return buffer.array(); + } + + @Override + public void deserialize(ByteBuffer buffer) { + int usernameLength = buffer.get(); + + byte[] username = new byte[usernameLength]; + buffer.get(username); + + this.asset.delegate.username = new String(username); + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/DelegateResignation.java b/src/main/java/org/arkecosystem/crypto/transactions/types/DelegateResignation.java new file mode 100644 index 00000000..ed3821a1 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/DelegateResignation.java @@ -0,0 +1,31 @@ +package org.arkecosystem.crypto.transactions.types; + +import java.nio.ByteBuffer; +import java.util.HashMap; +import org.arkecosystem.crypto.enums.CoreTransactionTypes; +import org.arkecosystem.crypto.enums.TransactionTypeGroup; + +public class DelegateResignation extends Transaction { + @Override + public int getTransactionType() { + return CoreTransactionTypes.DELEGATE_RESIGNATION.getValue(); + } + + @Override + public int getTransactionTypeGroup() { + return TransactionTypeGroup.CORE.getValue(); + } + + @Override + public HashMap assetToHashMap() { + return null; + } + + @Override + public byte[] serialize() { + return new byte[0]; + } + + @Override + public void deserialize(ByteBuffer buffer) {} +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/HtlcClaim.java b/src/main/java/org/arkecosystem/crypto/transactions/types/HtlcClaim.java new file mode 100644 index 00000000..24c6437f --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/HtlcClaim.java @@ -0,0 +1,54 @@ +package org.arkecosystem.crypto.transactions.types; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.HashMap; +import org.arkecosystem.crypto.encoding.Hex; +import org.arkecosystem.crypto.enums.CoreTransactionTypes; +import org.arkecosystem.crypto.enums.TransactionTypeGroup; + +public class HtlcClaim extends Transaction { + + @Override + public int getTransactionType() { + return CoreTransactionTypes.HTLC_CLAIM.getValue(); + } + + @Override + public int getTransactionTypeGroup() { + return TransactionTypeGroup.CORE.getValue(); + } + + @Override + public HashMap assetToHashMap() { + HashMap asset = new HashMap<>(); + + HashMap claim = new HashMap<>(); + claim.put("lockTransactionId", this.asset.htlcClaimAsset.lockTransactionId); + claim.put("unlockSecret", this.asset.htlcClaimAsset.unlockSecret); + + asset.put("claim", claim); + return asset; + } + + @Override + public byte[] serialize() { + ByteBuffer buffer = ByteBuffer.allocate(32 + 32); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.put(Hex.decode(this.asset.htlcClaimAsset.lockTransactionId)); + buffer.put(Hex.decode(this.asset.htlcClaimAsset.unlockSecret)); + return buffer.array(); + } + + @Override + public void deserialize(ByteBuffer buffer) { + byte[] lockTransactionIdBuf = new byte[32]; + buffer.get(lockTransactionIdBuf); + + byte[] unlockSecret = new byte[32]; + buffer.get(unlockSecret); + + this.asset.htlcClaimAsset.lockTransactionId = Hex.encode(lockTransactionIdBuf); + this.asset.htlcClaimAsset.unlockSecret = Hex.encode(unlockSecret); + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/HtlcLock.java b/src/main/java/org/arkecosystem/crypto/transactions/types/HtlcLock.java new file mode 100644 index 00000000..c188db12 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/HtlcLock.java @@ -0,0 +1,71 @@ +package org.arkecosystem.crypto.transactions.types; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.HashMap; +import org.arkecosystem.crypto.encoding.Base58; +import org.arkecosystem.crypto.encoding.Hex; +import org.arkecosystem.crypto.enums.CoreTransactionTypes; +import org.arkecosystem.crypto.enums.HtlcLockExpirationType; +import org.arkecosystem.crypto.enums.TransactionTypeGroup; +import org.arkecosystem.crypto.transactions.TransactionAsset; + +public class HtlcLock extends Transaction { + + @Override + public int getTransactionType() { + return CoreTransactionTypes.HTLC_LOCK.getValue(); + } + + @Override + public int getTransactionTypeGroup() { + return TransactionTypeGroup.CORE.getValue(); + } + + @Override + public boolean hasVendorField() { + return true; + } + + @Override + public HashMap assetToHashMap() { + HashMap asset = new HashMap<>(); + + HashMap lock = new HashMap<>(); + lock.put("secretHash", this.asset.htlcLockAsset.secretHash); + + HashMap expiration = new HashMap<>(); + expiration.put("type", this.asset.htlcLockAsset.expiration.type.getValue()); + expiration.put("value", this.asset.htlcLockAsset.expiration.value); + lock.put("expiration", expiration); + + asset.put("lock", lock); + return asset; + } + + @Override + public byte[] serialize() { + ByteBuffer buffer = ByteBuffer.allocate(8 + 32 + 1 + 4 + 21); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.putLong(this.amount); + buffer.put(Hex.decode(this.asset.htlcLockAsset.secretHash)); + buffer.put((byte) this.asset.htlcLockAsset.expiration.type.getValue()); + buffer.putInt(this.asset.htlcLockAsset.expiration.value); + buffer.put(Base58.decodeChecked(this.recipientId)); + return buffer.array(); + } + + @Override + public void deserialize(ByteBuffer buffer) { + this.amount = buffer.getLong(); + byte[] secretHash = new byte[32]; + buffer.get(secretHash); + this.asset.htlcLockAsset.secretHash = Hex.encode(secretHash); + this.asset.htlcLockAsset.expiration = + new TransactionAsset.Expiration( + HtlcLockExpirationType.values()[buffer.get() - 1], buffer.getInt()); + byte[] recipientId = new byte[21]; + buffer.get(recipientId); + this.recipientId = Base58.encodeChecked(recipientId); + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/HtlcRefund.java b/src/main/java/org/arkecosystem/crypto/transactions/types/HtlcRefund.java new file mode 100644 index 00000000..4e82dca7 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/HtlcRefund.java @@ -0,0 +1,47 @@ +package org.arkecosystem.crypto.transactions.types; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.HashMap; +import org.arkecosystem.crypto.encoding.Hex; +import org.arkecosystem.crypto.enums.CoreTransactionTypes; +import org.arkecosystem.crypto.enums.TransactionTypeGroup; + +public class HtlcRefund extends Transaction { + + @Override + public int getTransactionType() { + return CoreTransactionTypes.HTLC_REFUND.getValue(); + } + + @Override + public int getTransactionTypeGroup() { + return TransactionTypeGroup.CORE.getValue(); + } + + @Override + public HashMap assetToHashMap() { + HashMap asset = new HashMap<>(); + + HashMap lockTransactionId = new HashMap<>(); + lockTransactionId.put("lockTransactionId", this.asset.htlcRefundAsset.lockTransactionId); + + asset.put("refund", lockTransactionId); + return asset; + } + + @Override + public byte[] serialize() { + ByteBuffer buffer = ByteBuffer.allocate(32); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.put(Hex.decode(this.asset.htlcRefundAsset.lockTransactionId)); + return buffer.array(); + } + + @Override + public void deserialize(ByteBuffer buffer) { + byte[] lockTransactionIdBuffer = new byte[32]; + buffer.get(lockTransactionIdBuffer); + this.asset.htlcRefundAsset.lockTransactionId = Hex.encode(lockTransactionIdBuffer); + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/Ipfs.java b/src/main/java/org/arkecosystem/crypto/transactions/types/Ipfs.java new file mode 100644 index 00000000..78eb2e99 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/Ipfs.java @@ -0,0 +1,54 @@ +package org.arkecosystem.crypto.transactions.types; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.HashMap; +import org.arkecosystem.crypto.encoding.Base58; +import org.arkecosystem.crypto.enums.CoreTransactionTypes; +import org.arkecosystem.crypto.enums.TransactionTypeGroup; + +public class Ipfs extends Transaction { + + @Override + public int getTransactionType() { + return CoreTransactionTypes.IPFS.getValue(); + } + + @Override + public int getTransactionTypeGroup() { + return TransactionTypeGroup.CORE.getValue(); + } + + @Override + public HashMap assetToHashMap() { + HashMap asset = new HashMap<>(); + asset.put("ipfs", this.asset.ipfs); + return asset; + } + + @Override + public byte[] serialize() { + byte[] ipfsBuffer = Base58.decode(this.asset.ipfs); + ByteBuffer buffer = ByteBuffer.allocate(ipfsBuffer.length); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.put(ipfsBuffer); + return buffer.array(); + } + + @Override + public void deserialize(ByteBuffer buffer) { + byte hashFunction = buffer.get(); + byte ipfsHashLength = buffer.get(); + byte[] hashBuffer = new byte[ipfsHashLength]; + buffer.get(hashBuffer); + + byte[] ipfsBuffer = + ByteBuffer.allocate(ipfsHashLength + 2) + .put(hashFunction) + .put(ipfsHashLength) + .put(hashBuffer) + .array(); + + this.asset.ipfs = Base58.encode(ipfsBuffer); + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/MultiPayment.java b/src/main/java/org/arkecosystem/crypto/transactions/types/MultiPayment.java new file mode 100644 index 00000000..f15fefb9 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/MultiPayment.java @@ -0,0 +1,66 @@ +package org.arkecosystem.crypto.transactions.types; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.HashMap; +import org.arkecosystem.crypto.encoding.Base58; +import org.arkecosystem.crypto.enums.CoreTransactionTypes; +import org.arkecosystem.crypto.enums.TransactionTypeGroup; +import org.arkecosystem.crypto.transactions.TransactionAsset; + +public class MultiPayment extends Transaction { + + @Override + public int getTransactionType() { + return CoreTransactionTypes.MULTI_PAYMENT.getValue(); + } + + @Override + public int getTransactionTypeGroup() { + return TransactionTypeGroup.CORE.getValue(); + } + + @Override + public boolean hasVendorField() { + return true; + } + + @Override + public HashMap assetToHashMap() { + HashMap asset = new HashMap<>(); + ArrayList> payments = new ArrayList<>(); + for (TransactionAsset.Payment current : this.asset.multiPayment.payments) { + HashMap payment = new HashMap<>(); + payment.put("amount", String.valueOf(current.amount)); + payment.put("recipientId", current.recipientId); + payments.add(payment); + } + asset.put("payments", payments); + return asset; + } + + @Override + public byte[] serialize() { + ByteBuffer buffer = ByteBuffer.allocate(2 + this.asset.multiPayment.payments.size() * 29); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.putShort((short) this.asset.multiPayment.payments.size()); + for (TransactionAsset.Payment current : this.asset.multiPayment.payments) { + buffer.putLong(current.amount); + buffer.put(Base58.decodeChecked(current.recipientId)); + } + return buffer.array(); + } + + @Override + public void deserialize(ByteBuffer buffer) { + int paymentLength = buffer.getShort() & 0xff; + for (int i = 0; i < paymentLength; i++) { + byte[] recipientId = new byte[21]; + long amount = buffer.getLong(); + buffer.get(recipientId); + this.asset.multiPayment.payments.add( + new TransactionAsset.Payment(amount, Base58.encodeChecked(recipientId))); + } + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/MultiSignatureRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/types/MultiSignatureRegistration.java new file mode 100644 index 00000000..14f23df3 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/MultiSignatureRegistration.java @@ -0,0 +1,38 @@ +package org.arkecosystem.crypto.transactions.types; + +import java.nio.ByteBuffer; +import java.util.HashMap; +import org.arkecosystem.crypto.enums.CoreTransactionTypes; +import org.arkecosystem.crypto.enums.TransactionTypeGroup; + +public class MultiSignatureRegistration extends Transaction { + + @Override + public int getTransactionType() { + return CoreTransactionTypes.MULTI_SIGNATURE_REGISTRATION.getValue(); + } + + @Override + public int getTransactionTypeGroup() { + return TransactionTypeGroup.CORE.getValue(); + } + + @Override + public HashMap assetToHashMap() { + + throw new UnsupportedOperationException( + "MultiSignatureRegistration is not supported in java sdk"); + } + + @Override + public byte[] serialize() { + throw new UnsupportedOperationException( + "MultiSignatureRegistration is not supported in java sdk"); + } + + @Override + public void deserialize(ByteBuffer buffer) { + throw new UnsupportedOperationException( + "MultiSignatureRegistration is not supported in java sdk"); + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/SecondSignatureRegistration.java b/src/main/java/org/arkecosystem/crypto/transactions/types/SecondSignatureRegistration.java new file mode 100644 index 00000000..8606c8b6 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/SecondSignatureRegistration.java @@ -0,0 +1,50 @@ +package org.arkecosystem.crypto.transactions.types; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.HashMap; +import org.arkecosystem.crypto.encoding.Hex; +import org.arkecosystem.crypto.enums.CoreTransactionTypes; +import org.arkecosystem.crypto.enums.TransactionTypeGroup; + +public class SecondSignatureRegistration extends Transaction { + @Override + public int getTransactionType() { + return CoreTransactionTypes.SECOND_SIGNATURE_REGISTRATION.getValue(); + } + + @Override + public int getTransactionTypeGroup() { + return TransactionTypeGroup.CORE.getValue(); + } + + @Override + public HashMap assetToHashMap() { + HashMap asset = new HashMap<>(); + + HashMap publicKey = new HashMap<>(); + publicKey.put("publicKey", this.asset.signature.publicKey); + + asset.put("signature", publicKey); + return asset; + } + + @Override + public byte[] serialize() { + ByteBuffer buffer = ByteBuffer.allocate(33); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.put(Hex.decode(this.asset.signature.publicKey)); + return buffer.array(); + } + + @Override + public void deserialize(ByteBuffer buffer) { + byte[] publicKeyBuffer = new byte[33]; + buffer.get(publicKeyBuffer); + this.asset.signature.publicKey = Hex.encode(publicKeyBuffer); + + byte[] signatureBuffer = new byte[buffer.remaining()]; + buffer.get(signatureBuffer); + this.signature = Hex.encode(signatureBuffer); + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/Transaction.java b/src/main/java/org/arkecosystem/crypto/transactions/types/Transaction.java new file mode 100644 index 00000000..a1342236 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/Transaction.java @@ -0,0 +1,143 @@ +package org.arkecosystem.crypto.transactions.types; + +import com.google.gson.GsonBuilder; +import java.nio.ByteBuffer; +import java.util.HashMap; +import org.arkecosystem.crypto.encoding.Hex; +import org.arkecosystem.crypto.identities.PrivateKey; +import org.arkecosystem.crypto.transactions.Serializer; +import org.arkecosystem.crypto.transactions.TransactionAsset; +import org.bitcoinj.core.ECKey; +import org.bitcoinj.core.Sha256Hash; +import org.bitcoinj.core.SignatureDecodeException; + +public abstract class Transaction { + + public int version; + public int network; + public int typeGroup; + public int type; + public long nonce; + public String senderPublicKey; + public long fee = 0L; + public String vendorField; + public String vendorFieldHex; + public TransactionAsset asset = new TransactionAsset(); + public String signature; + public String secondSignature; + public long amount = 0L; + public int expiration; + public String recipientId; + public String id; + + public void computeId() { + this.id = this.getId(); + } + + public String getId() { + return Hex.encode(Sha256Hash.hash(new Serializer(this).serialize(false, false))); + } + + public Transaction sign(String passphrase) { + ECKey privateKey = PrivateKey.fromPassphrase(passphrase); + + this.senderPublicKey = privateKey.getPublicKeyAsHex(); + this.signature = + Hex.encode( + privateKey + .sign(Sha256Hash.of(Serializer.serialize(this, true, true))) + .encodeToDER()); + + return this; + } + + public Transaction secondSign(String passphrase) { + ECKey privateKey = PrivateKey.fromPassphrase(passphrase); + + this.secondSignature = + Hex.encode( + privateKey + .sign(Sha256Hash.of(Serializer.serialize(this, false, true))) + .encodeToDER()); + + return this; + } + + public boolean verify() { + ECKey keys = ECKey.fromPublicOnly(Hex.decode(this.senderPublicKey)); + + byte[] signature = Hex.decode(this.signature); + byte[] bytes = Serializer.serialize(this, true, true); + + try { + return ECKey.verify(Sha256Hash.hash(bytes), signature, keys.getPubKey()); + } catch (SignatureDecodeException e) { + return false; + } + } + + public boolean secondVerify(String secondPublicKey) { + ECKey keys = ECKey.fromPublicOnly(Hex.decode(secondPublicKey)); + + byte[] signature = Hex.decode(this.secondSignature); + byte[] bytes = Serializer.serialize(this, false, true); + + try { + return ECKey.verify(Sha256Hash.hash(bytes), signature, keys.getPubKey()); + } catch (SignatureDecodeException e) { + return false; + } + } + + public String toJson() { + GsonBuilder gsonBuilder = new GsonBuilder(); + return gsonBuilder.create().toJson(this.toHashMap()); + } + + public HashMap toHashMap() { + HashMap map = new HashMap(); + map.put("network", this.network); + map.put("id", this.id); + map.put("amount", String.valueOf(this.amount)); + map.put("fee", String.valueOf(this.fee)); + map.put("recipientId", this.recipientId); + map.put("signature", this.signature); + map.put("senderPublicKey", this.senderPublicKey); + map.put("type", this.type); + map.put("version", this.version); + map.put("nonce", String.valueOf(this.nonce)); + map.put("typeGroup", this.typeGroup); + + if (this.secondSignature != null) { + map.put("secondSignature", this.secondSignature); + } + + if (this.vendorField != null && !this.vendorField.isEmpty()) { + map.put("vendorField", this.vendorField); + } + + if (this.expiration > 0) { + map.put("expiration", this.expiration); + } + + HashMap asset = this.assetToHashMap(); + if (asset != null && !asset.isEmpty()) { + map.put("asset", asset); + } + return map; + } + + public abstract byte[] serialize(); + + public abstract void deserialize(ByteBuffer buffer); + + public abstract int getTransactionType(); + + public abstract int getTransactionTypeGroup(); + + public abstract HashMap assetToHashMap(); + + public boolean hasVendorField() { + return false; + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/Transfer.java b/src/main/java/org/arkecosystem/crypto/transactions/types/Transfer.java new file mode 100644 index 00000000..30567260 --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/Transfer.java @@ -0,0 +1,50 @@ +package org.arkecosystem.crypto.transactions.types; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.HashMap; +import org.arkecosystem.crypto.encoding.Base58; +import org.arkecosystem.crypto.enums.CoreTransactionTypes; +import org.arkecosystem.crypto.enums.TransactionTypeGroup; + +public class Transfer extends Transaction { + @Override + public int getTransactionType() { + return CoreTransactionTypes.TRANSFER.getValue(); + } + + @Override + public int getTransactionTypeGroup() { + return TransactionTypeGroup.CORE.getValue(); + } + + @Override + public boolean hasVendorField() { + return true; + } + + @Override + public HashMap assetToHashMap() { + return null; + } + + @Override + public byte[] serialize() { + ByteBuffer buffer = ByteBuffer.allocate(33); + buffer.order(ByteOrder.LITTLE_ENDIAN); + buffer.putLong(this.amount); + buffer.putInt(this.expiration); + buffer.put(Base58.decodeChecked(this.recipientId)); + return buffer.array(); + } + + @Override + public void deserialize(ByteBuffer buffer) { + this.amount = buffer.getLong(); + this.expiration = buffer.getInt(); + + byte[] recipientId = new byte[21]; + buffer.get(recipientId); + this.recipientId = Base58.encodeChecked(recipientId); + } +} diff --git a/src/main/java/org/arkecosystem/crypto/transactions/types/Vote.java b/src/main/java/org/arkecosystem/crypto/transactions/types/Vote.java new file mode 100644 index 00000000..e4d0c2ed --- /dev/null +++ b/src/main/java/org/arkecosystem/crypto/transactions/types/Vote.java @@ -0,0 +1,57 @@ +package org.arkecosystem.crypto.transactions.types; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import org.arkecosystem.crypto.encoding.Hex; +import org.arkecosystem.crypto.enums.CoreTransactionTypes; +import org.arkecosystem.crypto.enums.TransactionTypeGroup; + +public class Vote extends Transaction { + @Override + public int getTransactionType() { + return CoreTransactionTypes.VOTE.getValue(); + } + + @Override + public int getTransactionTypeGroup() { + return TransactionTypeGroup.CORE.getValue(); + } + + @Override + public HashMap assetToHashMap() { + HashMap asset = new HashMap<>(); + asset.put("votes", this.asset.votes); + return asset; + } + + @Override + public byte[] serialize() { + ByteBuffer buffer = ByteBuffer.allocate(1 + this.asset.votes.size() * 34); + buffer.order(ByteOrder.LITTLE_ENDIAN); + + List votes = new ArrayList<>(this.asset.votes); + for (int i = 0; i < votes.size(); i++) { + votes.set( + i, (votes.get(i).startsWith("+") ? "01" : "00") + (votes.get(i).substring(1))); + } + + buffer.put((byte) votes.size()); + buffer.put(Hex.decode(String.join("", votes))); + return buffer.array(); + } + + @Override + public void deserialize(ByteBuffer buffer) { + int voteLength = buffer.get(); + for (int i = 0; i < voteLength; i++) { + byte[] voteBuffer = new byte[34]; + buffer.get(voteBuffer); + String vote = Hex.encode(voteBuffer); + vote = (vote.startsWith("01") ? '+' : '-') + vote.substring(2); + this.asset.votes.add(vote); + } + } +} diff --git a/src/test/java/org/arkecosystem/crypto/configuration/FeeTest.java b/src/test/java/org/arkecosystem/crypto/configuration/FeeTest.java deleted file mode 100644 index 1ecf537a..00000000 --- a/src/test/java/org/arkecosystem/crypto/configuration/FeeTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.arkecosystem.crypto.configuration; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.HashMap; -import java.util.Map; -import org.arkecosystem.crypto.enums.CoreTransactionTypes; -import org.junit.jupiter.api.Test; - -class FeeTest { - - @Test - void get() { - long fee = Fee.getCoreFee(CoreTransactionTypes.TRANSFER.getValue()); - assertEquals(10_000_000, fee); - } - - @Test - void set() { - Map fees = new HashMap<>(); - fees.put(500, 1L); - Fee.set(1001, fees); - long fee = Fee.getFee(1001, 500); - assertEquals(1L, fee); - } -} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/FixtureLoader.java b/src/test/java/org/arkecosystem/crypto/transactions/FixtureLoader.java index 67258896..11607e8d 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/FixtureLoader.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/FixtureLoader.java @@ -7,6 +7,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import org.arkecosystem.crypto.transactions.types.Transaction; public class FixtureLoader { diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationBuilderTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationBuilderTest.java new file mode 100644 index 00000000..ab5ffbed --- /dev/null +++ b/src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationBuilderTest.java @@ -0,0 +1,38 @@ +package org.arkecosystem.crypto.transactions.builder; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.arkecosystem.crypto.transactions.types.Transaction; +import org.junit.jupiter.api.Test; + +class DelegateRegistrationBuilderTest { + @Test + void build() { + Transaction actual = + new DelegateRegistrationBuilder() + .username("java") + .version(2) + .nonce(3) + .sign("this is a top secret passphrase") + .transaction; + + assertTrue(actual.verify()); + } + + @Test + void buildSecondSignature() { + Transaction actual = + new DelegateRegistrationBuilder() + .username("java") + .version(2) + .nonce(3) + .sign("this is a top secret passphrase") + .secondSign("this is a top secret second passphrase") + .transaction; + + assertTrue(actual.verify()); + assertTrue( + actual.secondVerify( + "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609")); + } +} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationTest.java deleted file mode 100644 index f84bd51b..00000000 --- a/src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateRegistrationTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.arkecosystem.crypto.transactions.Transaction; -import org.junit.jupiter.api.Test; - -public class DelegateRegistrationTest { - - @Test - void build() { - Transaction actualV1 = - new DelegateRegistration() - .username("java") - .version(1) - .sign("this is a top secret passphrase") - .transaction; - - assertTrue(actualV1.verify()); - - Transaction actualV2 = - new DelegateRegistration() - .username("java") - .version(2) - .nonce(3) - .sign("this is a top secret passphrase") - .transaction; - - assertTrue(actualV2.verify()); - } - - @Test - void buildSecondSignature() { - Transaction actualV1 = - new DelegateRegistration() - .username("java") - .sign("this is a top secret passphrase") - .secondSign("this is a top secret second passphrase") - .transaction; - - assertTrue(actualV1.verify()); - assertTrue( - actualV1.secondVerify( - "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609")); - - Transaction actualV2 = - new DelegateRegistration() - .username("java") - .version(2) - .nonce(3) - .sign("this is a top secret passphrase") - .secondSign("this is a top secret second passphrase") - .transaction; - - assertTrue(actualV2.verify()); - assertTrue( - actualV2.secondVerify( - "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609")); - } -} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateResignationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateResignationBuilderTest.java similarity index 82% rename from src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateResignationTest.java rename to src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateResignationBuilderTest.java index 03aa0651..51426db0 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateResignationTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/builder/DelegateResignationBuilderTest.java @@ -2,15 +2,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class DelegateResignationTest { - +public class DelegateResignationBuilderTest { @Test void build() { Transaction actual = - new DelegateResignation() + new DelegateResignationBuilder() .version(2) .nonce(3) .sign("this is a top secret passphrase") @@ -22,7 +21,7 @@ void build() { @Test void buildSecondSignature() { Transaction actual = - new DelegateResignation() + new DelegateResignationBuilder() .version(2) .nonce(3) .sign("this is a top secret passphrase") diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcClaimTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcClaimBuilderTest.java similarity index 88% rename from src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcClaimTest.java rename to src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcClaimBuilderTest.java index 4760e8d8..c72eb008 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcClaimTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcClaimBuilderTest.java @@ -2,14 +2,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class HtlcClaimTest { +class HtlcClaimBuilderTest { @Test void build() { Transaction actual = - new HtlcClaim() + new HtlcClaimBuilder() .htlcClaimAsset( "943c220691e711c39c79d437ce185748a0018940e1a4144293af9d05627d2eb4", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") @@ -23,7 +23,7 @@ void build() { @Test void buildSecondSignature() { Transaction actual = - new HtlcClaim() + new HtlcClaimBuilder() .htlcClaimAsset( "943c220691e711c39c79d437ce185748a0018940e1a4144293af9d05627d2eb4", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcLockTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcLockBuilderTest.java similarity index 85% rename from src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcLockTest.java rename to src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcLockBuilderTest.java index e0fc9126..ffd05ba0 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcLockTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcLockBuilderTest.java @@ -3,15 +3,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import org.arkecosystem.crypto.enums.HtlcLockExpirationType; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class HtlcLockTest { +class HtlcLockBuilderTest { @Test void build() { Transaction actual = - new HtlcLock() - .amount(1) + new HtlcLockBuilder() + .amount(1000000) .recipientId("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25") .secretHash( "0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454") @@ -26,8 +26,8 @@ void build() { @Test void buildSecondSignature() { Transaction actual = - new HtlcLock() - .amount(1) + new HtlcLockBuilder() + .amount(1000000) .recipientId("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25") .secretHash( "0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454") diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcRefundTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcRefundBuilderTest.java similarity index 87% rename from src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcRefundTest.java rename to src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcRefundBuilderTest.java index f9c603a8..8a2d202c 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcRefundTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/builder/HtlcRefundBuilderTest.java @@ -2,14 +2,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class HtlcRefundTest { +class HtlcRefundBuilderTest { @Test void build() { Transaction actual = - new HtlcRefund() + new HtlcRefundBuilder() .htlcRefundAsset( "943c220691e711c39c79d437ce185748a0018940e1a4144293af9d05627d2eb4") .nonce(3) @@ -22,7 +22,7 @@ void build() { @Test void buildSecondSignature() { Transaction actual = - new HtlcRefund() + new HtlcRefundBuilder() .htlcRefundAsset( "943c220691e711c39c79d437ce185748a0018940e1a4144293af9d05627d2eb4") .nonce(3) diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/IpfsTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/IpfsBuilderTest.java similarity index 86% rename from src/test/java/org/arkecosystem/crypto/transactions/builder/IpfsTest.java rename to src/test/java/org/arkecosystem/crypto/transactions/builder/IpfsBuilderTest.java index 0be28596..c15bc84b 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/builder/IpfsTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/builder/IpfsBuilderTest.java @@ -2,15 +2,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class IpfsTest { +class IpfsBuilderTest { @Test - void build() { + void passphrase() { Transaction actualV2 = - new Ipfs() + new IpfsBuilder() .ipfsAsset("QmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w") .version(2) .nonce(3) @@ -23,7 +23,7 @@ void build() { @Test void buildSecondSignature() { Transaction actualV2 = - new Ipfs() + new IpfsBuilder() .ipfsAsset("QmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w") .version(2) .nonce(3) diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentBuilderTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentBuilderTest.java new file mode 100644 index 00000000..08c2fd21 --- /dev/null +++ b/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentBuilderTest.java @@ -0,0 +1,42 @@ +package org.arkecosystem.crypto.transactions.builder; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.arkecosystem.crypto.transactions.types.Transaction; +import org.junit.jupiter.api.Test; + +class MultiPaymentBuilderTest { + @Test + void build() { + Transaction actual = + new MultiPaymentBuilder() + .vendorField("This is a transaction from Java") + .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 1) + .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 2) + .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 3) + .vendorField("This is a transaction from Java") + .sign("this is a top secret passphrase") + .transaction; + + assertTrue(actual.verify()); + } + + @Test + void buildSecondSignature() { + Transaction actual = + new MultiPaymentBuilder() + .vendorField("This is a transaction from Java") + .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 1) + .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 2) + .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 3) + .vendorField("This is a transaction from Java") + .sign("this is a top secret passphrase") + .secondSign("this is a top secret second passphrase") + .transaction; + + assertTrue(actual.verify()); + assertTrue( + actual.secondVerify( + "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609")); + } +} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentTest.java deleted file mode 100644 index 12777a34..00000000 --- a/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiPaymentTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.arkecosystem.crypto.configuration.Network; -import org.arkecosystem.crypto.networks.Devnet; -import org.arkecosystem.crypto.networks.Testnet; -import org.arkecosystem.crypto.transactions.Transaction; -import org.junit.jupiter.api.Test; - -public class MultiPaymentTest { - @Test - void build() { - Transaction actual = - new MultiPayment() - .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 1) - .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 2) - .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 3) - .vendorField("This is a transaction from Java") - .sign("this is a top secret passphrase") - .transaction; - - assertTrue(actual.verify()); - } - - @Test - void buildDevnet() { - Network.set(new Devnet()); - Transaction actual = - new MultiPayment() - .addPayment("DNA6BqdX2mYw3PtPfGmEz2bGyyCA9hbaED", 1) - .addPayment("D65rqoZU7U4FdqLVF9KsEF9GBtvwDEVTBt", 2) - .addPayment("D88ZXZ5MaeZFA6xrJPSgJ92qWVWY1462dD", 3) - .vendorField("Zan Vendor Field arghhh") - .nonce(2) - .sign( - "nurse organ hub theory mad strike desert add heavy deposit immune inform") - .transaction; - - System.out.println(actual.toJson()); - System.out.println(actual.serialize()); - assertTrue(actual.verify()); - } - - @Test - void buildTestnet() { - Network.set(new Testnet()); - Transaction actual = - new MultiPayment() - .addPayment("AHXtmB84sTZ9Zd35h9Y1vfFvPE2Xzqj8ri", 1) - .addPayment("AZFEPTWnn2Sn8wDZgCRF8ohwKkrmk2AZi1", 2) - .nonce(1) - .sign("this is a top secret passphrase") - .transaction; - - System.out.println(actual.toJson()); - System.out.println(actual.serialize()); - assertTrue(actual.verify()); - } - - @Test - void buildSecondSignature() { - Transaction actual = - new MultiPayment() - .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 1) - .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 2) - .addPayment("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25", 3) - .vendorField("This is a transaction from Java") - .sign("this is a top secret passphrase") - .secondSign("this is a top secret second passphrase") - .transaction; - - assertTrue(actual.verify()); - } -} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationBuilderTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationBuilderTest.java new file mode 100644 index 00000000..c29a0c20 --- /dev/null +++ b/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationBuilderTest.java @@ -0,0 +1,18 @@ +package org.arkecosystem.crypto.transactions.builder; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class MultiSignatureRegistrationBuilderTest { + + @Test + void build() { + MultiSignatureRegistrationBuilder actual = new MultiSignatureRegistrationBuilder(); + Throwable exception = + assertThrows(UnsupportedOperationException.class, () -> actual.sign("passphrase")); + assertEquals( + "MultiSignatureRegistration is not supported in java sdk", exception.getMessage()); + } +} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationTest.java deleted file mode 100644 index 2c141819..00000000 --- a/src/test/java/org/arkecosystem/crypto/transactions/builder/MultiSignatureRegistrationTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Arrays; -import org.arkecosystem.crypto.transactions.Transaction; -import org.junit.jupiter.api.Test; - -public class MultiSignatureRegistrationTest { - - @Test - void build() { - Transaction actualV1 = - new MultiSignatureRegistration() - .min(2) - .lifetime(255) - .keysgroup( - Arrays.asList( - "03a02b9d5fdd1307c2ee4652ba54d492d1fd11a7d1bb3f3a44c4a05e79f19de933", - "13a02b9d5fdd1307c2ee4652ba54d492d1fd11a7d1bb3f3a44c4a05e79f19de933", - "23a02b9d5fdd1307c2ee4652ba54d492d1fd11a7d1bb3f3a44c4a05e79f19de933")) - .sign("this is a top secret passphrase") - .transaction; - - assertTrue(actualV1.verify()); - } - - @Test - void buildSecondSignature() { - Transaction actual = - new MultiSignatureRegistration() - .min(2) - .lifetime(255) - .keysgroup( - Arrays.asList( - "03a02b9d5fdd1307c2ee4652ba54d492d1fd11a7d1bb3f3a44c4a05e79f19de933", - "13a02b9d5fdd1307c2ee4652ba54d492d1fd11a7d1bb3f3a44c4a05e79f19de933", - "23a02b9d5fdd1307c2ee4652ba54d492d1fd11a7d1bb3f3a44c4a05e79f19de933")) - .sign("this is a top secret passphrase") - .secondSign("this is a top secret second passphrase") - .transaction; - - assertTrue(actual.verify()); - assertTrue( - actual.secondVerify( - "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609")); - } -} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationBuilderTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationBuilderTest.java new file mode 100644 index 00000000..238358a9 --- /dev/null +++ b/src/test/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationBuilderTest.java @@ -0,0 +1,22 @@ +package org.arkecosystem.crypto.transactions.builder; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.arkecosystem.crypto.transactions.types.Transaction; +import org.junit.jupiter.api.Test; + +class SecondSignatureRegistrationBuilderTest { + + @Test + void passphrase() { + Transaction actualV2 = + new SecondSignatureRegistrationBuilder() + .signature("this is a top secret second passphrase'") + .version(2) + .nonce(3) + .sign("this is a top secret passphrase") + .transaction; + + assertTrue(actualV2.verify()); + } +} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationTest.java deleted file mode 100644 index f4f89d62..00000000 --- a/src/test/java/org/arkecosystem/crypto/transactions/builder/SecondSignatureRegistrationTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.arkecosystem.crypto.transactions.Transaction; -import org.junit.jupiter.api.Test; - -public class SecondSignatureRegistrationTest { - - @Test - void build() { - Transaction actualV1 = - new SecondSignatureRegistration() - .signature("this is a top secret second passphrase'") - .version(1) - .sign("this is a top secret passphrase") - .transaction; - - assertTrue(actualV1.verify()); - - Transaction actualV2 = - new SecondSignatureRegistration() - .signature("this is a top secret second passphrase'") - .version(2) - .nonce(3) - .sign("this is a top secret passphrase") - .transaction; - - assertTrue(actualV2.verify()); - } -} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/TransferBuilderTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/TransferBuilderTest.java new file mode 100644 index 00000000..96328f20 --- /dev/null +++ b/src/test/java/org/arkecosystem/crypto/transactions/builder/TransferBuilderTest.java @@ -0,0 +1,45 @@ +package org.arkecosystem.crypto.transactions.builder; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.arkecosystem.crypto.transactions.types.Transaction; +import org.junit.jupiter.api.Test; + +class TransferBuilderTest { + + @Test + void build() { + Transaction actual = + new TransferBuilder() + .recipient("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25") + .amount(133380000000L) + .expiration(100000) + .vendorField("This is a transaction from Java") + .version(2) + .nonce(3) + .sign("this is a top secret passphrase") + .transaction; + + assertTrue(actual.verify()); + } + + @Test + void buildSecondSignature() { + Transaction actualV2 = + new TransferBuilder() + .recipient("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25") + .amount(133380000000L) + .expiration(100000) + .vendorField("This is a transaction from Java") + .version(2) + .nonce(3) + .sign("this is a top secret passphrase") + .secondSign("this is a top secret second passphrase") + .transaction; + + assertTrue(actualV2.verify()); + assertTrue( + actualV2.secondVerify( + "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609")); + } +} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/TransferTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/TransferTest.java deleted file mode 100644 index f5f3ade8..00000000 --- a/src/test/java/org/arkecosystem/crypto/transactions/builder/TransferTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.arkecosystem.crypto.transactions.builder; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.arkecosystem.crypto.transactions.Transaction; -import org.junit.jupiter.api.Test; - -public class TransferTest { - - @Test - void build() { - Transaction actualV1 = - new Transfer() - .recipient("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25") - .amount(133380000000L) - .vendorField("This is a transaction from Java") - .version(1) - .sign("this is a top secret passphrase") - .transaction; - - assertTrue(actualV1.verify()); - - Transaction actualV2 = - new Transfer() - .recipient("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25") - .amount(133380000000L) - .vendorField("This is a transaction from Java") - .version(2) - .nonce(3) - .sign("this is a top secret passphrase") - .transaction; - - assertTrue(actualV2.verify()); - } - - @Test - void buildSecondSignature() { - Transaction actualV1 = - new Transfer() - .recipient("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25") - .amount(133380000000L) - .vendorField("This is a transaction from Java") - .version(1) - .sign("this is a top secret passphrase") - .secondSign("this is a top secret second passphrase") - .transaction; - - assertTrue(actualV1.verify()); - assertTrue( - actualV1.secondVerify( - "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609")); - - Transaction actualV2 = - new Transfer() - .recipient("AXoXnFi4z1Z6aFvjEYkDVCtBGW2PaRiM25") - .amount(133380000000L) - .vendorField("This is a transaction from Java") - .version(2) - .nonce(3) - .sign("this is a top secret passphrase") - .secondSign("this is a top secret second passphrase") - .transaction; - - assertTrue(actualV2.verify()); - assertTrue( - actualV2.secondVerify( - "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609")); - } -} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/builder/VoteTest.java b/src/test/java/org/arkecosystem/crypto/transactions/builder/VoteBuilderTest.java similarity index 51% rename from src/test/java/org/arkecosystem/crypto/transactions/builder/VoteTest.java rename to src/test/java/org/arkecosystem/crypto/transactions/builder/VoteBuilderTest.java index abe2410e..cd11fac5 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/builder/VoteTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/builder/VoteBuilderTest.java @@ -3,57 +3,41 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class VoteTest { - +class VoteBuilderTest { @Test void build() { - Transaction actualV1 = - new Vote() - .votes( + Transaction actual = + new VoteBuilder() + .addVotes( Arrays.asList( - "'+034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192'")) - .version(1) + "+034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192")) + .version(2) + .nonce(3) .sign("this is a top secret passphrase") .transaction; - assertTrue(actualV1.verify()); + assertTrue(actual.verify()); - Transaction actualV2 = - new Vote() - .votes( - Arrays.asList( - "+034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192")) + Transaction actual2 = + new VoteBuilder() + .addVote( + "+034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192") .version(2) .nonce(3) .sign("this is a top secret passphrase") .transaction; - assertTrue(actualV2.verify()); + assertTrue(actual2.verify()); } @Test void buildSecondSignature() { - Transaction actualV1 = - new Vote() - .votes( - Arrays.asList( - "'+034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192'")) - .version(1) - .sign("this is a top secret passphrase") - .secondSign("this is a top secret second passphrase") - .transaction; - - assertTrue(actualV1.verify()); - assertTrue( - actualV1.secondVerify( - "03699e966b2525f9088a6941d8d94f7869964a000efe65783d78ac82e1199fe609")); - Transaction actualV2 = - new Vote() - .votes( + new VoteBuilder() + .addVotes( Arrays.asList( "+034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192")) .version(2) diff --git a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/DelegateRegistrationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/DelegateRegistrationTest.java index f295e91f..12953b7d 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/DelegateRegistrationTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/DelegateRegistrationTest.java @@ -6,101 +6,59 @@ import org.arkecosystem.crypto.enums.TransactionTypeGroup; import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -class DelegateRegistrationTest { +public class DelegateRegistrationTest { @Test void passphrase() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/delegate_registration/passphrase"); - LinkedTreeMap dataV1 = - (LinkedTreeMap) fixtureV1.get("data"); - - Transaction actualV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - assertEquals(((Double) dataV1.get("type")).intValue(), actualV1.type); - assertEquals(((Double) dataV1.get("amount")).longValue(), actualV1.amount); - assertEquals(((Double) dataV1.get("fee")).longValue(), actualV1.fee); - assertEquals(((Double) dataV1.get("timestamp")).intValue(), actualV1.timestamp); - assertEquals(dataV1.get("senderPublicKey").toString(), actualV1.senderPublicKey); - assertEquals(dataV1.get("signature").toString(), actualV1.signature); - assertEquals(dataV1.get("id").toString(), actualV1.id); + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/delegate-registration-sign"); - LinkedTreeMap assetV1 = - (LinkedTreeMap) - ((LinkedTreeMap) dataV1.get("asset")).get("delegate"); - assertEquals((assetV1.get("username")), actualV1.asset.delegate.username); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - // V2 tests - LinkedTreeMap fixtureV2 = - FixtureLoader.load("transactions/v2-ecdsa/delegate-registration-sign"); - LinkedTreeMap dataV2 = - (LinkedTreeMap) fixtureV2.get("data"); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction actualV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - assertEquals(((Double) dataV2.get("type")).intValue(), actualV2.type); - assertEquals(TransactionTypeGroup.CORE.getValue(), actualV2.typeGroup); - assertEquals((Long.valueOf((String) dataV2.get("fee"))), actualV2.fee); - assertEquals((Long.valueOf((String) dataV2.get("nonce"))), actualV2.nonce); - assertEquals(dataV2.get("senderPublicKey").toString(), actualV2.senderPublicKey); - assertEquals(dataV2.get("signature").toString(), actualV2.signature); - assertEquals(dataV2.get("id").toString(), actualV2.id); + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); - LinkedTreeMap assetV2 = + LinkedTreeMap asset = (LinkedTreeMap) - ((LinkedTreeMap) dataV2.get("asset")).get("delegate"); - assertEquals((assetV2.get("username")), actualV2.asset.delegate.username); + ((LinkedTreeMap) data.get("asset")).get("delegate"); + assertEquals((asset.get("username")), actual.asset.delegate.username); } @Test void secondPassphrase() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/delegate_registration/second-passphrase"); - LinkedTreeMap dataV1 = - (LinkedTreeMap) fixtureV1.get("data"); - - Transaction actualV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - assertEquals(((Double) dataV1.get("type")).intValue(), actualV1.type); - assertEquals(((Double) dataV1.get("amount")).longValue(), actualV1.amount); - assertEquals(((Double) dataV1.get("fee")).longValue(), actualV1.fee); - assertEquals(((Double) dataV1.get("timestamp")).intValue(), actualV1.timestamp); - assertEquals(dataV1.get("senderPublicKey").toString(), actualV1.senderPublicKey); - assertEquals(dataV1.get("signature").toString(), actualV1.signature); - assertEquals(dataV1.get("signSignature").toString(), actualV1.signSignature); - assertEquals(dataV1.get("id").toString(), actualV1.id); + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/delegate-registration-secondSign"); - LinkedTreeMap assetV1 = - (LinkedTreeMap) - ((LinkedTreeMap) dataV1.get("asset")).get("delegate"); - assertEquals((assetV1.get("username")), actualV1.asset.delegate.username); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - // V2 tests - LinkedTreeMap fixtureV2 = - FixtureLoader.load("transactions/v2-ecdsa/delegate-registration-secondSign"); - LinkedTreeMap dataV2 = - (LinkedTreeMap) fixtureV2.get("data"); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction actualV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - assertEquals(((Double) dataV2.get("type")).intValue(), actualV2.type); - assertEquals(TransactionTypeGroup.CORE.getValue(), actualV2.typeGroup); - assertEquals((Long.valueOf((String) dataV2.get("fee"))), actualV2.fee); - assertEquals((Long.valueOf((String) dataV2.get("nonce"))), actualV2.nonce); - assertEquals(dataV2.get("senderPublicKey").toString(), actualV2.senderPublicKey); - assertEquals(dataV2.get("signature").toString(), actualV2.signature); - assertEquals(dataV2.get("secondSignature").toString(), actualV2.signSignature); - assertEquals(dataV2.get("secondSignature").toString(), actualV2.secondSignature); - assertEquals(dataV2.get("id").toString(), actualV2.id); + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); - LinkedTreeMap assetV2 = + LinkedTreeMap asset = (LinkedTreeMap) - ((LinkedTreeMap) dataV2.get("asset")).get("delegate"); - assertEquals((assetV2.get("username")), actualV2.asset.delegate.username); + ((LinkedTreeMap) data.get("asset")).get("delegate"); + assertEquals((asset.get("username")), actual.asset.delegate.username); + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/DelegateResignationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/DelegateResignationTest.java index 623631e1..ff8d4b07 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/DelegateResignationTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/DelegateResignationTest.java @@ -7,23 +7,27 @@ import org.arkecosystem.crypto.enums.TransactionTypeGroup; import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class DelegateResignationTest { +class DelegateResignationTest { @Test void passphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/delegate-resignation-sign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); - assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); assertEquals(data.get("id").toString(), actual.id); @@ -34,19 +38,22 @@ void passphrase() { void secondPassphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/delegate-resignation-secondSign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); - assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); - assertEquals(data.get("secondSignature").toString(), actual.signSignature); - assertEquals(data.get("secondSignature").toString(), actual.secondSignature); assertEquals(data.get("id").toString(), actual.id); assertNull(data.get("asset")); + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcClaimTest.java b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcClaimTest.java index 20b72a49..fe1740d5 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcClaimTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcClaimTest.java @@ -6,23 +6,29 @@ import org.arkecosystem.crypto.enums.TransactionTypeGroup; import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; public class HtlcClaimTest { + @Test void passphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-claim-sign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); - assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); LinkedTreeMap asset = (LinkedTreeMap) @@ -30,25 +36,26 @@ void passphrase() { assertEquals( (asset.get("lockTransactionId")), actual.asset.htlcClaimAsset.lockTransactionId); assertEquals((asset.get("unlockSecret")), actual.asset.htlcClaimAsset.unlockSecret); - - assertEquals(data.get("id").toString(), actual.id); } @Test void secondPassphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-claim-secondSign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); - assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); - assertEquals(data.get("secondSignature").toString(), actual.signSignature); - assertEquals(data.get("secondSignature").toString(), actual.secondSignature); + assertEquals(data.get("id").toString(), actual.id); LinkedTreeMap asset = (LinkedTreeMap) @@ -57,6 +64,6 @@ void secondPassphrase() { (asset.get("lockTransactionId")), actual.asset.htlcClaimAsset.lockTransactionId); assertEquals((asset.get("unlockSecret")), actual.asset.htlcClaimAsset.unlockSecret); - assertEquals(data.get("id").toString(), actual.id); + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcLockTest.java b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcLockTest.java index 29b6a8be..ca3fb658 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcLockTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcLockTest.java @@ -6,7 +6,7 @@ import org.arkecosystem.crypto.enums.TransactionTypeGroup; import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; public class HtlcLockTest { @@ -14,63 +14,143 @@ public class HtlcLockTest { void passphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-lock-sign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); - assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); LinkedTreeMap asset = (LinkedTreeMap) ((LinkedTreeMap) data.get("asset")).get("lock"); + assertEquals((asset.get("secretHash")), actual.asset.htlcLockAsset.secretHash); LinkedTreeMap assetExpiration = - (LinkedTreeMap) - ((LinkedTreeMap) asset.get("expiration")); + ((LinkedTreeMap) asset.get("expiration")); assertEquals( ((Double) assetExpiration.get("type")).intValue(), actual.asset.htlcLockAsset.expiration.type.getValue()); assertEquals( ((Double) assetExpiration.get("value")).intValue(), actual.asset.htlcLockAsset.expiration.value); + assertEquals((Long.valueOf((String) data.get("amount"))), actual.amount); + } + @Test + void passphraseVendorField() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/htlc-lock-with-vendor-field-sign"); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); assertEquals(data.get("id").toString(), actual.id); + + LinkedTreeMap asset = + (LinkedTreeMap) + ((LinkedTreeMap) data.get("asset")).get("lock"); + + assertEquals((asset.get("secretHash")), actual.asset.htlcLockAsset.secretHash); + LinkedTreeMap assetExpiration = + ((LinkedTreeMap) asset.get("expiration")); + assertEquals( + ((Double) assetExpiration.get("type")).intValue(), + actual.asset.htlcLockAsset.expiration.type.getValue()); + assertEquals( + ((Double) assetExpiration.get("value")).intValue(), + actual.asset.htlcLockAsset.expiration.value); + assertEquals((Long.valueOf((String) data.get("amount"))), actual.amount); + assertEquals(data.get("vendorField").toString(), actual.vendorField); } @Test void secondPassphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-lock-secondSign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); - assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); - assertEquals(data.get("secondSignature").toString(), actual.signSignature); - assertEquals(data.get("secondSignature").toString(), actual.secondSignature); + assertEquals(data.get("id").toString(), actual.id); LinkedTreeMap asset = (LinkedTreeMap) ((LinkedTreeMap) data.get("asset")).get("lock"); + assertEquals((asset.get("secretHash")), actual.asset.htlcLockAsset.secretHash); LinkedTreeMap assetExpiration = - (LinkedTreeMap) - ((LinkedTreeMap) asset.get("expiration")); + ((LinkedTreeMap) asset.get("expiration")); assertEquals( ((Double) assetExpiration.get("type")).intValue(), actual.asset.htlcLockAsset.expiration.type.getValue()); assertEquals( ((Double) assetExpiration.get("value")).intValue(), actual.asset.htlcLockAsset.expiration.value); + assertEquals((Long.valueOf((String) data.get("amount"))), actual.amount); + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); + } + @Test + void secondPassphraseVendorField() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/htlc-lock-with-vendor-field-secondSign"); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); assertEquals(data.get("id").toString(), actual.id); + + LinkedTreeMap asset = + (LinkedTreeMap) + ((LinkedTreeMap) data.get("asset")).get("lock"); + + assertEquals((asset.get("secretHash")), actual.asset.htlcLockAsset.secretHash); + LinkedTreeMap assetExpiration = + ((LinkedTreeMap) asset.get("expiration")); + assertEquals( + ((Double) assetExpiration.get("type")).intValue(), + actual.asset.htlcLockAsset.expiration.type.getValue()); + assertEquals( + ((Double) assetExpiration.get("value")).intValue(), + actual.asset.htlcLockAsset.expiration.value); + assertEquals((Long.valueOf((String) data.get("amount"))), actual.amount); + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); + assertEquals(data.get("vendorField").toString(), actual.vendorField); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcRefundTest.java b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcRefundTest.java index ab32b5bb..1db04734 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcRefundTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/HtlcRefundTest.java @@ -6,7 +6,7 @@ import org.arkecosystem.crypto.enums.TransactionTypeGroup; import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; public class HtlcRefundTest { @@ -15,40 +15,46 @@ public class HtlcRefundTest { void passphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-refund-sign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); - assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); LinkedTreeMap asset = (LinkedTreeMap) ((LinkedTreeMap) data.get("asset")).get("refund"); assertEquals( (asset.get("lockTransactionId")), actual.asset.htlcRefundAsset.lockTransactionId); - - assertEquals(data.get("id").toString(), actual.id); } @Test void secondPassphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-refund-secondSign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); - assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); - assertEquals(data.get("secondSignature").toString(), actual.signSignature); - assertEquals(data.get("secondSignature").toString(), actual.secondSignature); + assertEquals(data.get("id").toString(), actual.id); LinkedTreeMap asset = (LinkedTreeMap) @@ -56,6 +62,6 @@ void secondPassphrase() { assertEquals( (asset.get("lockTransactionId")), actual.asset.htlcRefundAsset.lockTransactionId); - assertEquals(data.get("id").toString(), actual.id); + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/IpfsTest.java b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/IpfsTest.java index 8cc64764..8a15ae91 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/IpfsTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/IpfsTest.java @@ -6,23 +6,26 @@ import org.arkecosystem.crypto.enums.TransactionTypeGroup; import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class IpfsTest { - +class IpfsTest { @Test void passphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/ipfs-sign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); - assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); assertEquals(data.get("id").toString(), actual.id); @@ -34,19 +37,22 @@ void passphrase() { void secondPassphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/ipfs-secondSign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); - assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); - assertEquals(data.get("secondSignature").toString(), actual.signSignature); - assertEquals(data.get("secondSignature").toString(), actual.secondSignature); assertEquals(data.get("id").toString(), actual.id); + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); LinkedTreeMap asset = ((LinkedTreeMap) data.get("asset")); assertEquals((asset.get("ipfs")), actual.asset.ipfs); } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/MultiPaymentTest.java b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/MultiPaymentTest.java index 28924e0f..d5e28006 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/MultiPaymentTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/MultiPaymentTest.java @@ -7,22 +7,57 @@ import org.arkecosystem.crypto.enums.TransactionTypeGroup; import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class MultiPaymentTest { +class MultiPaymentTest { @Test void passphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/multi-payment-sign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); + + LinkedTreeMap asset = (LinkedTreeMap) data.get("asset"); + ArrayList payments = ((ArrayList) asset.get("payments")); + for (int i = 0; i < payments.size(); i++) { + String recipientId = + (String) ((LinkedTreeMap) payments.get(i)).get("recipientId"); + String amount = + ((String) ((LinkedTreeMap) payments.get(i)).get("amount")); + assertEquals(recipientId, actual.asset.multiPayment.payments.get(i).recipientId); + assertEquals(Long.valueOf(amount), actual.asset.multiPayment.payments.get(i).amount); + } + } + + @Test + void passphraseVendorField() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/multi-payment-with-vendor-field-sign"); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); assertEquals(data.get("id").toString(), actual.id); @@ -36,23 +71,27 @@ void passphrase() { assertEquals(recipientId, actual.asset.multiPayment.payments.get(i).recipientId); assertEquals(Long.valueOf(amount), actual.asset.multiPayment.payments.get(i).amount); } + + assertEquals(data.get("vendorField").toString(), actual.vendorField); } @Test void secondPassphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/multi-payment-secondSign"); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); - assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(((Double) data.get("type")).intValue(), actual.type); assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); assertEquals(data.get("signature").toString(), actual.signature); - assertEquals(data.get("secondSignature").toString(), actual.signSignature); - assertEquals(data.get("secondSignature").toString(), actual.secondSignature); assertEquals(data.get("id").toString(), actual.id); LinkedTreeMap asset = (LinkedTreeMap) data.get("asset"); @@ -66,6 +105,41 @@ void secondPassphrase() { assertEquals(Long.valueOf(amount), actual.asset.multiPayment.payments.get(i).amount); } + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); + } + + @Test + void secondPassphraseVendorField() { + LinkedTreeMap fixture = + FixtureLoader.load( + "transactions/v2-ecdsa/multi-payment-with-vendor-field-secondSign"); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); assertEquals(data.get("id").toString(), actual.id); + + LinkedTreeMap asset = (LinkedTreeMap) data.get("asset"); + ArrayList payments = ((ArrayList) asset.get("payments")); + for (int i = 0; i < payments.size(); i++) { + String recipientId = + (String) ((LinkedTreeMap) payments.get(i)).get("recipientId"); + String amount = + ((String) ((LinkedTreeMap) payments.get(i)).get("amount")); + assertEquals(recipientId, actual.asset.multiPayment.payments.get(i).recipientId); + assertEquals(Long.valueOf(amount), actual.asset.multiPayment.payments.get(i).amount); + } + + assertEquals(data.get("vendorField").toString(), actual.vendorField); + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/MultiSignatureRegistrationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/MultiSignatureRegistrationTest.java deleted file mode 100644 index 2da0eb02..00000000 --- a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/MultiSignatureRegistrationTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.arkecosystem.crypto.transactions.deserializers; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.google.gson.internal.LinkedTreeMap; -import org.arkecosystem.crypto.transactions.Deserializer; -import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Transaction; -import org.junit.jupiter.api.Test; - -class MultiSignatureRegistrationTest { - - @Test - void passphrase() { - LinkedTreeMap fixture = - FixtureLoader.load("transactions/V1/multi_signature_registration/passphrase"); - LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - - Transaction actual = new Deserializer().deserialize(fixture.get("serialized").toString()); - assertEquals(((Double) data.get("type")).intValue(), actual.type); - assertEquals(((Double) data.get("amount")).longValue(), actual.amount); - assertEquals(((Double) data.get("fee")).longValue(), actual.fee); - assertEquals(((Double) data.get("timestamp")).intValue(), actual.timestamp); - assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); - assertEquals(data.get("signature").toString(), actual.signature); - assertEquals(data.get("signatures"), actual.signatures); - - LinkedTreeMap asset = - (LinkedTreeMap) - ((LinkedTreeMap) data.get("asset")).get("multisignature"); - assertEquals(((Double) asset.get("min")).intValue(), actual.asset.multisignature.min); - assertEquals( - ((Double) asset.get("lifetime")).intValue(), actual.asset.multisignature.lifetime); - assertEquals((asset.get("keysgroup")), actual.asset.multisignature.keysgroup); - - assertEquals(data.get("id").toString(), actual.id); - } -} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/SecondSignatureRegistrationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/SecondSignatureRegistrationTest.java index 628e4fc0..4cf8ddb3 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/SecondSignatureRegistrationTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/SecondSignatureRegistrationTest.java @@ -6,34 +6,33 @@ import org.arkecosystem.crypto.enums.TransactionTypeGroup; import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -class SecondSignatureRegistrationTest { +public class SecondSignatureRegistrationTest { @Test void passphrase() { - LinkedTreeMap fixtureV2 = + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/second-signature-registration"); - LinkedTreeMap dataV2 = - (LinkedTreeMap) fixtureV2.get("data"); - Transaction actualV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); - assertEquals(((Double) dataV2.get("type")).intValue(), actualV2.type); - assertEquals(TransactionTypeGroup.CORE.getValue(), actualV2.typeGroup); - assertEquals((Long.valueOf((String) dataV2.get("fee"))), actualV2.fee); - assertEquals((Long.valueOf((String) dataV2.get("nonce"))), actualV2.nonce); - assertEquals(dataV2.get("senderPublicKey").toString(), actualV2.senderPublicKey); - assertEquals(dataV2.get("signature").toString(), actualV2.signature); - assertEquals(dataV2.get("id").toString(), actualV2.id); + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); LinkedTreeMap assetV2 = (LinkedTreeMap) - ((LinkedTreeMap) dataV2.get("asset")).get("signature"); - assertEquals((assetV2.get("publicKey")), actualV2.asset.signature.publicKey); - - assertEquals(dataV2.get("id").toString(), actualV2.id); + ((LinkedTreeMap) data.get("asset")).get("signature"); + assertEquals((assetV2.get("publicKey")), actual.asset.signature.publicKey); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/TransferTest.java b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/TransferTest.java index 724eca2b..40860ed8 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/TransferTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/TransferTest.java @@ -6,174 +6,108 @@ import org.arkecosystem.crypto.enums.TransactionTypeGroup; import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; class TransferTest { @Test void passphrase() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/transfer/passphrase"); - LinkedTreeMap dataV1 = - (LinkedTreeMap) fixtureV1.get("data"); - - Transaction actualV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - assertEquals(((Double) dataV1.get("type")).intValue(), actualV1.type); - assertEquals(((Double) dataV1.get("amount")).longValue(), actualV1.amount); - assertEquals(((Double) dataV1.get("fee")).longValue(), actualV1.fee); - assertEquals(dataV1.get("recipientId").toString(), actualV1.recipientId); - assertEquals(((Double) dataV1.get("timestamp")).intValue(), actualV1.timestamp); - assertEquals(dataV1.get("senderPublicKey").toString(), actualV1.senderPublicKey); - assertEquals(dataV1.get("signature").toString(), actualV1.signature); - assertEquals(dataV1.get("id").toString(), actualV1.id); - - // V2 tests - LinkedTreeMap fixtureV2 = + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/transfer-sign"); - LinkedTreeMap dataV2 = - (LinkedTreeMap) fixtureV2.get("data"); - - Transaction actualV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - assertEquals(((Double) dataV2.get("type")).intValue(), actualV2.type); - assertEquals(TransactionTypeGroup.CORE.getValue(), actualV2.typeGroup); - assertEquals((Long.valueOf((String) dataV2.get("fee"))), actualV2.fee); - assertEquals(dataV2.get("recipientId").toString(), actualV2.recipientId); - assertEquals((Long.valueOf((String) dataV2.get("nonce"))), actualV2.nonce); - assertEquals(dataV2.get("senderPublicKey").toString(), actualV2.senderPublicKey); - assertEquals(dataV2.get("signature").toString(), actualV2.signature); - assertEquals(dataV2.get("id").toString(), actualV2.id); - - assertEquals((Long.valueOf((String) dataV2.get("amount"))), actualV2.amount); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); + + assertEquals(data.get("recipientId").toString(), actual.recipientId); + assertEquals((Long.valueOf((String) data.get("amount"))), actual.amount); + assertEquals(((Double) data.get("expiration")).intValue(), actual.expiration); } @Test void passphraseVendorField() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/transfer/passphrase-with-vendor-field"); - LinkedTreeMap dataV1 = - (LinkedTreeMap) fixtureV1.get("data"); - - Transaction actualV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - assertEquals(((Double) dataV1.get("type")).intValue(), actualV1.type); - assertEquals(((Double) dataV1.get("amount")).longValue(), actualV1.amount); - assertEquals(((Double) dataV1.get("fee")).longValue(), actualV1.fee); - assertEquals(dataV1.get("recipientId").toString(), actualV1.recipientId); - assertEquals(((Double) dataV1.get("timestamp")).intValue(), actualV1.timestamp); - assertEquals(dataV1.get("senderPublicKey").toString(), actualV1.senderPublicKey); - assertEquals(dataV1.get("vendorField").toString(), actualV1.vendorField); - assertEquals(dataV1.get("signature").toString(), actualV1.signature); - assertEquals(dataV1.get("id").toString(), actualV1.id); - - // V2 tests - LinkedTreeMap fixtureV2 = + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/transfer-with-vendor-field-sign"); - LinkedTreeMap dataV2 = - (LinkedTreeMap) fixtureV2.get("data"); - - Transaction actualV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - assertEquals(((Double) dataV2.get("type")).intValue(), actualV2.type); - assertEquals(TransactionTypeGroup.CORE.getValue(), actualV2.typeGroup); - assertEquals((Long.valueOf((String) dataV2.get("fee"))), actualV2.fee); - assertEquals(dataV2.get("recipientId").toString(), actualV2.recipientId); - assertEquals((Long.valueOf((String) dataV2.get("nonce"))), actualV2.nonce); - assertEquals(dataV2.get("senderPublicKey").toString(), actualV2.senderPublicKey); - assertEquals(dataV2.get("signature").toString(), actualV2.signature); - assertEquals(dataV2.get("id").toString(), actualV2.id); - - assertEquals((Long.valueOf((String) dataV2.get("amount"))), actualV2.amount); - assertEquals(dataV2.get("vendorField").toString(), actualV2.vendorField); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); + + assertEquals(data.get("recipientId").toString(), actual.recipientId); + assertEquals((Long.valueOf((String) data.get("amount"))), actual.amount); + assertEquals(((Double) data.get("expiration")).intValue(), actual.expiration); + assertEquals(data.get("vendorField").toString(), actual.vendorField); } @Test void secondPassphrase() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/transfer/second-passphrase"); - LinkedTreeMap dataV1 = - (LinkedTreeMap) fixtureV1.get("data"); - - Transaction actualV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - assertEquals(((Double) dataV1.get("type")).intValue(), actualV1.type); - assertEquals(((Double) dataV1.get("amount")).longValue(), actualV1.amount); - assertEquals(((Double) dataV1.get("fee")).longValue(), actualV1.fee); - assertEquals(dataV1.get("recipientId").toString(), actualV1.recipientId); - assertEquals(((Double) dataV1.get("timestamp")).intValue(), actualV1.timestamp); - assertEquals(dataV1.get("senderPublicKey").toString(), actualV1.senderPublicKey); - assertEquals(dataV1.get("signature").toString(), actualV1.signature); - assertEquals(dataV1.get("signSignature").toString(), actualV1.signSignature); - assertEquals(dataV1.get("id").toString(), actualV1.id); - - // V2 tests - LinkedTreeMap fixtureV2 = - FixtureLoader.load("transactions/v2-ecdsa/transfer-with-vendor-field-secondSign"); - LinkedTreeMap dataV2 = - (LinkedTreeMap) fixtureV2.get("data"); - - Transaction actualV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - assertEquals(((Double) dataV2.get("type")).intValue(), actualV2.type); - assertEquals(TransactionTypeGroup.CORE.getValue(), actualV2.typeGroup); - assertEquals((Long.valueOf((String) dataV2.get("fee"))), actualV2.fee); - assertEquals(dataV2.get("recipientId").toString(), actualV2.recipientId); - assertEquals((Long.valueOf((String) dataV2.get("nonce"))), actualV2.nonce); - assertEquals(dataV2.get("senderPublicKey").toString(), actualV2.senderPublicKey); - assertEquals(dataV2.get("signature").toString(), actualV2.signature); - assertEquals(dataV2.get("id").toString(), actualV2.id); - - assertEquals((Long.valueOf((String) dataV2.get("amount"))), actualV2.amount); - assertEquals(dataV2.get("secondSignature").toString(), actualV2.signSignature); - assertEquals(dataV2.get("secondSignature").toString(), actualV2.secondSignature); + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/transfer-secondSign"); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); + + assertEquals(data.get("recipientId").toString(), actual.recipientId); + assertEquals((Long.valueOf((String) data.get("amount"))), actual.amount); + assertEquals(((Double) data.get("expiration")).intValue(), actual.expiration); + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); } @Test void secondPassphraseVendorField() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/transfer/second-passphrase-with-vendor-field"); - LinkedTreeMap dataV1 = - (LinkedTreeMap) fixtureV1.get("data"); - - Transaction actualV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - assertEquals(((Double) dataV1.get("type")).intValue(), actualV1.type); - assertEquals(((Double) dataV1.get("amount")).longValue(), actualV1.amount); - assertEquals(((Double) dataV1.get("fee")).longValue(), actualV1.fee); - assertEquals(dataV1.get("recipientId").toString(), actualV1.recipientId); - assertEquals(((Double) dataV1.get("timestamp")).intValue(), actualV1.timestamp); - assertEquals(dataV1.get("senderPublicKey").toString(), actualV1.senderPublicKey); - assertEquals(dataV1.get("vendorField").toString(), actualV1.vendorField); - assertEquals(dataV1.get("signature").toString(), actualV1.signature); - assertEquals(dataV1.get("signSignature").toString(), actualV1.signSignature); - assertEquals(dataV1.get("id").toString(), actualV1.id); - - // V2 tests - LinkedTreeMap fixtureV2 = + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/transfer-with-vendor-field-secondSign"); - LinkedTreeMap dataV2 = - (LinkedTreeMap) fixtureV2.get("data"); - - Transaction actualV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - assertEquals(((Double) dataV2.get("type")).intValue(), actualV2.type); - assertEquals(TransactionTypeGroup.CORE.getValue(), actualV2.typeGroup); - assertEquals((Long.valueOf((String) dataV2.get("fee"))), actualV2.fee); - assertEquals(dataV2.get("recipientId").toString(), actualV2.recipientId); - assertEquals((Long.valueOf((String) dataV2.get("nonce"))), actualV2.nonce); - assertEquals(dataV2.get("senderPublicKey").toString(), actualV2.senderPublicKey); - assertEquals(dataV2.get("signature").toString(), actualV2.signature); - assertEquals(dataV2.get("id").toString(), actualV2.id); - - assertEquals((Long.valueOf((String) dataV2.get("amount"))), actualV2.amount); - assertEquals(dataV2.get("secondSignature").toString(), actualV2.signSignature); - assertEquals(dataV2.get("secondSignature").toString(), actualV2.secondSignature); - assertEquals(dataV2.get("vendorField").toString(), actualV2.vendorField); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); + + assertEquals(data.get("recipientId").toString(), actual.recipientId); + assertEquals((Long.valueOf((String) data.get("amount"))), actual.amount); + assertEquals(((Double) data.get("expiration")).intValue(), actual.expiration); + assertEquals(data.get("vendorField").toString(), actual.vendorField); + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/VoteTest.java b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/VoteTest.java index d3dfa977..100c97f9 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/deserializers/VoteTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/deserializers/VoteTest.java @@ -6,102 +6,104 @@ import org.arkecosystem.crypto.enums.TransactionTypeGroup; import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; class VoteTest { @Test - void passphrase() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/vote/passphrase"); - LinkedTreeMap dataV1 = - (LinkedTreeMap) fixtureV1.get("data"); - - Transaction actualV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - assertEquals(((Double) dataV1.get("type")).intValue(), actualV1.type); - assertEquals(((Double) dataV1.get("amount")).longValue(), actualV1.amount); - assertEquals(((Double) dataV1.get("fee")).longValue(), actualV1.fee); - assertEquals(dataV1.get("recipientId").toString(), actualV1.recipientId); - assertEquals(((Double) dataV1.get("timestamp")).intValue(), actualV1.timestamp); - assertEquals(dataV1.get("senderPublicKey").toString(), actualV1.senderPublicKey); - assertEquals(dataV1.get("signature").toString(), actualV1.signature); - - LinkedTreeMap assetV1 = (LinkedTreeMap) dataV1.get("asset"); - assertEquals((assetV1.get("votes")), actualV1.asset.votes); - - assertEquals(dataV1.get("id").toString(), actualV1.id); - - // V2 tests - LinkedTreeMap fixtureV2 = + void passphraseVote() { + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/vote-sign"); - LinkedTreeMap dataV2 = - (LinkedTreeMap) fixtureV2.get("data"); - - Transaction actualV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - assertEquals(((Double) dataV2.get("type")).intValue(), actualV2.type); - assertEquals(TransactionTypeGroup.CORE.getValue(), actualV2.typeGroup); - assertEquals((Long.valueOf((String) dataV2.get("fee"))), actualV2.fee); - assertEquals((Long.valueOf((String) dataV2.get("nonce"))), actualV2.nonce); - assertEquals(dataV2.get("senderPublicKey").toString(), actualV2.senderPublicKey); - assertEquals(dataV2.get("signature").toString(), actualV2.signature); - assertEquals(dataV2.get("id").toString(), actualV2.id); - - LinkedTreeMap assetV2 = (LinkedTreeMap) dataV2.get("asset"); - assertEquals((assetV2.get("votes")), actualV2.asset.votes); - - assertEquals(dataV2.get("id").toString(), actualV2.id); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); + + LinkedTreeMap assetV2 = (LinkedTreeMap) data.get("asset"); + assertEquals((assetV2.get("votes")), actual.asset.votes); + } + + @Test + void passphraseUnvote() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/unvote-sign"); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); + + LinkedTreeMap asset = (LinkedTreeMap) data.get("asset"); + assertEquals((asset.get("votes")), actual.asset.votes); } @Test - void secondPassphrase() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/vote/second-passphrase"); - LinkedTreeMap dataV1 = - (LinkedTreeMap) fixtureV1.get("data"); - - Transaction actualV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - assertEquals(((Double) dataV1.get("type")).intValue(), actualV1.type); - assertEquals(((Double) dataV1.get("amount")).longValue(), actualV1.amount); - assertEquals(((Double) dataV1.get("fee")).longValue(), actualV1.fee); - assertEquals(dataV1.get("recipientId").toString(), actualV1.recipientId); - assertEquals(((Double) dataV1.get("timestamp")).intValue(), actualV1.timestamp); - assertEquals(dataV1.get("senderPublicKey").toString(), actualV1.senderPublicKey); - assertEquals(dataV1.get("signature").toString(), actualV1.signature); - assertEquals(dataV1.get("signSignature").toString(), actualV1.signSignature); - - LinkedTreeMap assetV1 = (LinkedTreeMap) dataV1.get("asset"); - assertEquals((assetV1.get("votes")), actualV1.asset.votes); - - assertEquals(dataV1.get("id").toString(), actualV1.id); - - // V2 tests - LinkedTreeMap fixtureV2 = + void secondPassphraseVote() { + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/vote-secondSign"); - LinkedTreeMap dataV2 = - (LinkedTreeMap) fixtureV2.get("data"); - - Transaction actualV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - assertEquals(((Double) dataV2.get("type")).intValue(), actualV2.type); - assertEquals(TransactionTypeGroup.CORE.getValue(), actualV2.typeGroup); - assertEquals((Long.valueOf((String) dataV2.get("fee"))), actualV2.fee); - assertEquals((Long.valueOf((String) dataV2.get("nonce"))), actualV2.nonce); - assertEquals(dataV2.get("senderPublicKey").toString(), actualV2.senderPublicKey); - assertEquals(dataV2.get("signature").toString(), actualV2.signature); - assertEquals(dataV2.get("id").toString(), actualV2.id); - assertEquals((Long.valueOf((String) dataV2.get("amount"))), actualV2.amount); - assertEquals(dataV2.get("secondSignature").toString(), actualV2.signSignature); - assertEquals(dataV2.get("secondSignature").toString(), actualV2.secondSignature); - - LinkedTreeMap assetV2 = (LinkedTreeMap) dataV2.get("asset"); - assertEquals((assetV2.get("votes")), actualV2.asset.votes); - - assertEquals(dataV2.get("id").toString(), actualV2.id); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); + + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); + + LinkedTreeMap asset = (LinkedTreeMap) data.get("asset"); + assertEquals((asset.get("votes")), actual.asset.votes); + } + + @Test + void secondPassphraseUnvote() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/unvote-secondSign"); + + LinkedTreeMap data = (LinkedTreeMap) fixture.get("data"); + + Transaction actual = new Deserializer(fixture.get("serialized").toString()).deserialize(); + + assertEquals(((Double) data.get("version")).intValue(), actual.version); + assertEquals(((Double) data.get("network")).intValue(), actual.network); + assertEquals(TransactionTypeGroup.CORE.getValue(), actual.typeGroup); + assertEquals(((Double) data.get("type")).intValue(), actual.type); + assertEquals((Long.valueOf((String) data.get("nonce"))), actual.nonce); + assertEquals(data.get("senderPublicKey").toString(), actual.senderPublicKey); + assertEquals((Long.valueOf((String) data.get("fee"))), actual.fee); + assertEquals(data.get("signature").toString(), actual.signature); + assertEquals(data.get("id").toString(), actual.id); + + assertEquals(data.get("secondSignature").toString(), actual.secondSignature); + + LinkedTreeMap asset = (LinkedTreeMap) data.get("asset"); + assertEquals((asset.get("votes")), actual.asset.votes); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/serializers/DelegateRegistrationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/serializers/DelegateRegistrationTest.java index 1b9e7605..e05723fb 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/serializers/DelegateRegistrationTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/serializers/DelegateRegistrationTest.java @@ -7,54 +7,31 @@ import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; import org.arkecosystem.crypto.transactions.Serializer; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; class DelegateRegistrationTest { - @Test void passphrase() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/delegate_registration/passphrase"); - - Transaction transactionV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - String actualV1 = Hex.encode(new Serializer().serialize(transactionV1)); - - assertEquals(fixtureV1.get("serialized").toString(), actualV1); - - // V2 tests - LinkedTreeMap fixtureV2 = + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/delegate-registration-sign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction transactionV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - String actualV2 = Hex.encode(new Serializer().serialize(transactionV2)); + String actual = Hex.encode(Serializer.serialize(transaction)); - assertEquals(fixtureV2.get("serialized").toString(), actualV2); + assertEquals(fixture.get("serialized").toString(), actual); } @Test void secondPassphrase() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/delegate_registration/second-passphrase"); - - Transaction transactionV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - String actualV1 = Hex.encode(new Serializer().serialize(transactionV1)); - - assertEquals(fixtureV1.get("serialized").toString(), actualV1); - - // V2 tests - LinkedTreeMap fixtureV2 = + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/delegate-registration-secondSign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction transactionV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - String actualV2 = Hex.encode(new Serializer().serialize(transactionV2)); + String actual = Hex.encode(Serializer.serialize(transaction)); - assertEquals(fixtureV2.get("serialized").toString(), actualV2); + assertEquals(fixture.get("serialized").toString(), actual); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/serializers/DelegateResignationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/serializers/DelegateResignationTest.java index c9767c06..849c0de1 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/serializers/DelegateResignationTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/serializers/DelegateResignationTest.java @@ -7,10 +7,10 @@ import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; import org.arkecosystem.crypto.transactions.Serializer; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class DelegateResignationTest { +class DelegateResignationTest { @Test void passphrase() { @@ -18,8 +18,9 @@ void passphrase() { FixtureLoader.load("transactions/v2-ecdsa/delegate-resignation-sign"); Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); assertEquals(fixture.get("serialized").toString(), actual); } @@ -30,8 +31,9 @@ void secondPassphrase() { FixtureLoader.load("transactions/v2-ecdsa/delegate-resignation-secondSign"); Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); assertEquals(fixture.get("serialized").toString(), actual); } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcClaimTest.java b/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcClaimTest.java index 68ae14a8..6d982268 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcClaimTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcClaimTest.java @@ -7,19 +7,19 @@ import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; import org.arkecosystem.crypto.transactions.Serializer; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; public class HtlcClaimTest { - @Test void passphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-claim-sign"); - Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); + assertEquals(fixture.get("serialized").toString(), actual); } @@ -27,10 +27,10 @@ void passphrase() { void secondPassphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-claim-secondSign"); - Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); assertEquals(fixture.get("serialized").toString(), actual); } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcLockTest.java b/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcLockTest.java index cdf5126a..4bcae35c 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcLockTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcLockTest.java @@ -7,19 +7,31 @@ import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; import org.arkecosystem.crypto.transactions.Serializer; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class HtlcLockTest { - +class HtlcLockTest { @Test void passphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-lock-sign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); + assertEquals(fixture.get("serialized").toString(), actual); + } + + @Test + void passphraseVendorField() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/htlc-lock-with-vendor-field-sign"); Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); + assertEquals(fixture.get("serialized").toString(), actual); } @@ -27,10 +39,22 @@ void passphrase() { void secondPassphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-lock-secondSign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); + assertEquals(fixture.get("serialized").toString(), actual); + } + + @Test + void secondPassphraseVendorField() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/htlc-lock-with-vendor-field-secondSign"); Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); assertEquals(fixture.get("serialized").toString(), actual); } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcRefundTest.java b/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcRefundTest.java index 74073c83..f395f574 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcRefundTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/serializers/HtlcRefundTest.java @@ -7,18 +7,20 @@ import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; import org.arkecosystem.crypto.transactions.Serializer; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class HtlcRefundTest { +class HtlcRefundTest { + @Test void passphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-refund-sign"); - Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); + assertEquals(fixture.get("serialized").toString(), actual); } @@ -26,10 +28,10 @@ void passphrase() { void secondPassphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/htlc-refund-secondSign"); - Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); assertEquals(fixture.get("serialized").toString(), actual); } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/serializers/IpfsTest.java b/src/test/java/org/arkecosystem/crypto/transactions/serializers/IpfsTest.java index 1ee57bae..f6f0513f 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/serializers/IpfsTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/serializers/IpfsTest.java @@ -7,19 +7,19 @@ import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; import org.arkecosystem.crypto.transactions.Serializer; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class IpfsTest { +class IpfsTest { @Test void passphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/ipfs-sign"); - Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); assertEquals(fixture.get("serialized").toString(), actual); } @@ -28,10 +28,10 @@ void passphrase() { void secondPassphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/ipfs-secondSign"); - Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); assertEquals(fixture.get("serialized").toString(), actual); } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/serializers/MultiPaymentTest.java b/src/test/java/org/arkecosystem/crypto/transactions/serializers/MultiPaymentTest.java index 32ad3381..c3b56d9f 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/serializers/MultiPaymentTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/serializers/MultiPaymentTest.java @@ -7,20 +7,30 @@ import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; import org.arkecosystem.crypto.transactions.Serializer; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class MultiPaymentTest { - +class MultiPaymentTest { @Test void passphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/multi-payment-sign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); + assertEquals(fixture.get("serialized").toString(), actual); + } + + @Test + void passphraseVendorField() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/multi-payment-with-vendor-field-sign"); Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - System.out.println(transaction.toJson()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); assertEquals(fixture.get("serialized").toString(), actual); } @@ -29,10 +39,23 @@ void passphrase() { void secondPassphrase() { LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/multi-payment-secondSign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); + + assertEquals(fixture.get("serialized").toString(), actual); + } + @Test + void secondPassphraseVendorField() { + LinkedTreeMap fixture = + FixtureLoader.load( + "transactions/v2-ecdsa/multi-payment-with-vendor-field-secondSign"); Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); + new Deserializer(fixture.get("serialized").toString()).deserialize(); + + String actual = Hex.encode(Serializer.serialize(transaction)); assertEquals(fixture.get("serialized").toString(), actual); } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/serializers/MultiSignatureRegistrationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/serializers/MultiSignatureRegistrationTest.java deleted file mode 100644 index a08edc4a..00000000 --- a/src/test/java/org/arkecosystem/crypto/transactions/serializers/MultiSignatureRegistrationTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.arkecosystem.crypto.transactions.serializers; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.google.gson.internal.LinkedTreeMap; -import org.arkecosystem.crypto.encoding.Hex; -import org.arkecosystem.crypto.transactions.Deserializer; -import org.arkecosystem.crypto.transactions.FixtureLoader; -import org.arkecosystem.crypto.transactions.Serializer; -import org.arkecosystem.crypto.transactions.Transaction; -import org.junit.jupiter.api.Test; - -class MultiSignatureRegistrationTest { - - @Test - void passphrase() { - LinkedTreeMap fixture = - FixtureLoader.load("transactions/V1/multi_signature_registration/passphrase"); - - Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); - - assertEquals(fixture.get("serialized").toString(), actual); - } -} diff --git a/src/test/java/org/arkecosystem/crypto/transactions/serializers/SecondSignatureRegistrationTest.java b/src/test/java/org/arkecosystem/crypto/transactions/serializers/SecondSignatureRegistrationTest.java index 0fd3e861..6afa4324 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/serializers/SecondSignatureRegistrationTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/serializers/SecondSignatureRegistrationTest.java @@ -7,21 +7,22 @@ import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; import org.arkecosystem.crypto.transactions.Serializer; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -class SecondSignatureRegistrationTest { +public class SecondSignatureRegistrationTest { @Test void passphrase() { // V2 tests - LinkedTreeMap fixtureV2 = + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/second-signature-registration"); - Transaction transactionV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - String actualV2 = Hex.encode(new Serializer().serialize(transactionV2)); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); - assertEquals(fixtureV2.get("serialized").toString(), actualV2); + String actual = Hex.encode(Serializer.serialize(transaction)); + + assertEquals(fixture.get("serialized").toString(), actual); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/serializers/TransferTest.java b/src/test/java/org/arkecosystem/crypto/transactions/serializers/TransferTest.java index e5c87ee2..6cd796e9 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/serializers/TransferTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/serializers/TransferTest.java @@ -7,147 +7,56 @@ import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; import org.arkecosystem.crypto.transactions.Serializer; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; -public class TransferTest { +class TransferTest { @Test void passphrase() { - // V1 tests LinkedTreeMap fixture = - FixtureLoader.load("transactions/V1/transfer/passphrase"); - - Transaction transaction = - new Deserializer().deserialize(fixture.get("serialized").toString()); - String actual = Hex.encode(new Serializer().serialize(transaction)); - - assertEquals(fixture.get("serialized").toString(), actual); - - // V2 tests - LinkedTreeMap fixtureV2 = FixtureLoader.load("transactions/v2-ecdsa/transfer-sign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction transaction2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - String actual2 = Hex.encode(new Serializer().serialize(transaction2)); + String actual = Hex.encode(Serializer.serialize(transaction)); - assertEquals(fixtureV2.get("serialized").toString(), actual2); + assertEquals(fixture.get("serialized").toString(), actual); } @Test void passphraseVendorField() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/transfer/passphrase-with-vendor-field"); - - Transaction transactionV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - String actualV1 = Hex.encode(new Serializer().serialize(transactionV1)); - - assertEquals(fixtureV1.get("serialized").toString(), actualV1); - - // V2 tests - LinkedTreeMap fixtureV2 = - FixtureLoader.load("transactions/v2-ecdsa/transfer-with-vendor-field-sign"); - - Transaction transactionV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - String actualV2 = Hex.encode(new Serializer().serialize(transactionV2)); - - assertEquals(fixtureV2.get("serialized").toString(), actualV2); - } - - @Test - void passphraseVendorFieldHex() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/transfer/passphrase-with-vendor-field-hex"); - - Transaction transactionV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - String actualV1 = Hex.encode(new Serializer().serialize(transactionV1)); - - assertEquals(fixtureV1.get("serialized").toString(), actualV1); - - // V2 tests - LinkedTreeMap fixtureV2 = + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/transfer-with-vendor-field-sign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction transactionV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - String actualV2 = Hex.encode(new Serializer().serialize(transactionV2)); + String actual = Hex.encode(Serializer.serialize(transaction)); - assertEquals(fixtureV2.get("serialized").toString(), actualV2); + assertEquals(fixture.get("serialized").toString(), actual); } @Test void secondPassphrase() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/transfer/second-passphrase"); - - Transaction transactionV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - String actualV1 = Hex.encode(new Serializer().serialize(transactionV1)); - - assertEquals(fixtureV1.get("serialized").toString(), actualV1); - - // V2 tests - LinkedTreeMap fixtureV2 = + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/transfer-with-vendor-field-secondSign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction transactionV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - String actualV2 = Hex.encode(new Serializer().serialize(transactionV2)); + String actual = Hex.encode(Serializer.serialize(transaction)); - assertEquals(fixtureV2.get("serialized").toString(), actualV2); + assertEquals(fixture.get("serialized").toString(), actual); } @Test void secondPassphraseVendorField() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/transfer/second-passphrase-with-vendor-field"); - - Transaction transactionV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - String actualV1 = Hex.encode(new Serializer().serialize(transactionV1)); - - assertEquals(fixtureV1.get("serialized").toString(), actualV1); - - // V2 tests - LinkedTreeMap fixtureV2 = - FixtureLoader.load("transactions/v2-ecdsa/transfer-with-vendor-field-secondSign"); - - Transaction transactionV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - String actualV2 = Hex.encode(new Serializer().serialize(transactionV2)); - - assertEquals(fixtureV2.get("serialized").toString(), actualV2); - } - - @Test - void secondPassphraseVendorFieldHex() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load( - "transactions/V1/transfer/second-passphrase-with-vendor-field-hex"); - - Transaction transactionV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - String actualV1 = Hex.encode(new Serializer().serialize(transactionV1)); - - assertEquals(fixtureV1.get("serialized").toString(), actualV1); - - // V2 tests - LinkedTreeMap fixtureV2 = + LinkedTreeMap fixture = FixtureLoader.load("transactions/v2-ecdsa/transfer-with-vendor-field-secondSign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction transactionV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - String actualV2 = Hex.encode(new Serializer().serialize(transactionV2)); + String actual = Hex.encode(Serializer.serialize(transaction)); - assertEquals(fixtureV2.get("serialized").toString(), actualV2); + assertEquals(fixture.get("serialized").toString(), actual); } } diff --git a/src/test/java/org/arkecosystem/crypto/transactions/serializers/VoteTest.java b/src/test/java/org/arkecosystem/crypto/transactions/serializers/VoteTest.java index fa27a0ac..409f1daa 100644 --- a/src/test/java/org/arkecosystem/crypto/transactions/serializers/VoteTest.java +++ b/src/test/java/org/arkecosystem/crypto/transactions/serializers/VoteTest.java @@ -7,54 +7,55 @@ import org.arkecosystem.crypto.transactions.Deserializer; import org.arkecosystem.crypto.transactions.FixtureLoader; import org.arkecosystem.crypto.transactions.Serializer; -import org.arkecosystem.crypto.transactions.Transaction; +import org.arkecosystem.crypto.transactions.types.Transaction; import org.junit.jupiter.api.Test; class VoteTest { - @Test - void passphrase() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/vote/passphrase"); + void passphraseVote() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/vote-sign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction transactionV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - String actualV1 = Hex.encode(new Serializer().serialize(transactionV1)); + String actual = Hex.encode(Serializer.serialize(transaction)); - assertEquals(fixtureV1.get("serialized").toString(), actualV1); + assertEquals(fixture.get("serialized").toString(), actual); + } - // V2 tests - LinkedTreeMap fixtureV2 = - FixtureLoader.load("transactions/v2-ecdsa/vote-sign"); + @Test + void passphraseUnvote() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/unvote-sign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction transactionV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - String actualV2 = Hex.encode(new Serializer().serialize(transactionV2)); + String actual = Hex.encode(Serializer.serialize(transaction)); - assertEquals(fixtureV2.get("serialized").toString(), actualV2); + assertEquals(fixture.get("serialized").toString(), actual); } @Test - void secondPassphrase() { - // V1 tests - LinkedTreeMap fixtureV1 = - FixtureLoader.load("transactions/V1/vote/second-passphrase"); + void secondPassphraseVote() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/vote-secondSign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction transactionV1 = - new Deserializer().deserialize(fixtureV1.get("serialized").toString()); - String actualV1 = Hex.encode(new Serializer().serialize(transactionV1)); + String actual = Hex.encode(Serializer.serialize(transaction)); - assertEquals(fixtureV1.get("serialized").toString(), actualV1); + assertEquals(fixture.get("serialized").toString(), actual); + } - // V2 tests - LinkedTreeMap fixtureV2 = - FixtureLoader.load("transactions/v2-ecdsa/vote-secondSign"); + @Test + void secondPassphraseUnvote() { + LinkedTreeMap fixture = + FixtureLoader.load("transactions/v2-ecdsa/unvote-secondSign"); + Transaction transaction = + new Deserializer(fixture.get("serialized").toString()).deserialize(); - Transaction transactionV2 = - new Deserializer().deserialize(fixtureV2.get("serialized").toString()); - String actualV2 = Hex.encode(new Serializer().serialize(transactionV2)); + String actual = Hex.encode(Serializer.serialize(transaction)); - assertEquals(fixtureV2.get("serialized").toString(), actualV2); + assertEquals(fixture.get("serialized").toString(), actual); } } diff --git a/src/test/resources/transactions/v2-ecdsa/delegate-registration-multiSign.json b/src/test/resources/transactions/v2-ecdsa/delegate-registration-multiSign.json deleted file mode 100644 index aa18c641..00000000 --- a/src/test/resources/transactions/v2-ecdsa/delegate-registration-multiSign.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 2, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "2500000000", - "amount": "0", - "asset": { - "delegate": { - "username": "boldninja" - } - }, - "signature": "304502210094d93b799526337256850011fd9a065a944c5bb58e730882393be62a01991cd70220715d66eb3377b59f2b51ca9616e7c252cb66ebf40f96cf469987dd4a9aaa60cd", - "id": "59a41e4411c9fac688ac22a10ba88a6ef6f513b2b8de05c94793e5434b1eb2e5" - }, - "serialized": "ff02170100000002000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19200f90295000000000009626f6c646e696e6a61304502210094d93b799526337256850011fd9a065a944c5bb58e730882393be62a01991cd70220715d66eb3377b59f2b51ca9616e7c252cb66ebf40f96cf469987dd4a9aaa60cd" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/delegate-resignation-multiSign.json b/src/test/resources/transactions/v2-ecdsa/delegate-resignation-multiSign.json deleted file mode 100644 index 494e5359..00000000 --- a/src/test/resources/transactions/v2-ecdsa/delegate-resignation-multiSign.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 7, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "2500000000", - "amount": "0", - "signature": "3045022100aa113ddefb502d868219339d16b8d448c8e69c8e320664e12903cc84420c159d02201b6206c7cb9442f6ef07dd0824aeb0cc393d8f9f9909988da6687c44ef897070", - "id": "a8cf10c6a7d2e5c82bff0860f83f917f426bdd1ee25bd8d5dad2358973ce4ecb" - }, - "serialized": "ff02170100000007000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19200f9029500000000003045022100aa113ddefb502d868219339d16b8d448c8e69c8e320664e12903cc84420c159d02201b6206c7cb9442f6ef07dd0824aeb0cc393d8f9f9909988da6687c44ef897070" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/htlc-claim-multiSign.json b/src/test/resources/transactions/v2-ecdsa/htlc-claim-multiSign.json deleted file mode 100644 index 76e87284..00000000 --- a/src/test/resources/transactions/v2-ecdsa/htlc-claim-multiSign.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 9, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "0", - "amount": "0", - "asset": { - "claim": { - "lockTransactionId": "9c1a3815d49e0c9f78b872bfb017e825ea2db708158b70815526a830c85912b4", - "unlockSecret": "c27f1ce845d8c29eebc9006be932b604fd06755521b1a8b0be4204c65377151a" - } - }, - "signature": "3045022100f4115db125d14edd248b39459ae8a6d112f8d9cdbcf69da03dce597c048d99260220069d4a07229684f91b492979f0050400c323eb4096f586dedc101f0f5a3ac476", - "id": "fd6eb162c34dadcd66a5e86ce534a1df946b8fa4291ed17c085b252dafbdf30b" - }, - "serialized": "ff02170100000009000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed1920000000000000000009c1a3815d49e0c9f78b872bfb017e825ea2db708158b70815526a830c85912b4c27f1ce845d8c29eebc9006be932b604fd06755521b1a8b0be4204c65377151a3045022100f4115db125d14edd248b39459ae8a6d112f8d9cdbcf69da03dce597c048d99260220069d4a07229684f91b492979f0050400c323eb4096f586dedc101f0f5a3ac476" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/htlc-lock-multiSign.json b/src/test/resources/transactions/v2-ecdsa/htlc-lock-multiSign.json deleted file mode 100644 index ac0e1617..00000000 --- a/src/test/resources/transactions/v2-ecdsa/htlc-lock-multiSign.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 8, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "10000000", - "amount": "200000000", - "recipientId": "AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC", - "asset": { - "lock": { - "secretHash": "0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454", - "expiration": { - "type": 1, - "value": 1581339432 - } - } - }, - "signature": "3045022100968071560adef123ebc908bb11f46550339c52c997829f597a539e5616f79f8d0220533c0992b991b5d9a670ea1877cd5306bef5963b9a868fadf4122329fd4b2712", - "id": "cfb37ec05433841cd8d25c3e8d353dc519a6dcb583edd75085b671bff4075b40" - }, - "serialized": "ff02170100000008000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19280969800000000000000c2eb0b000000000f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454012853415e170995750207ecaf0ccf251c1265b92ad84f5536623045022100968071560adef123ebc908bb11f46550339c52c997829f597a539e5616f79f8d0220533c0992b991b5d9a670ea1877cd5306bef5963b9a868fadf4122329fd4b2712" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/htlc-lock-with-vendor-field-multiSign.json b/src/test/resources/transactions/v2-ecdsa/htlc-lock-with-vendor-field-multiSign.json deleted file mode 100644 index cea1f04f..00000000 --- a/src/test/resources/transactions/v2-ecdsa/htlc-lock-with-vendor-field-multiSign.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 8, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "10000000", - "amount": "200000000", - "vendorField": "this is a top secret vendor field", - "recipientId": "AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC", - "asset": { - "lock": { - "secretHash": "0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454", - "expiration": { - "type": 1, - "value": 1581339432 - } - } - }, - "signature": "304402206b83b7976c08bbc1f67a17d5481f498bdadd761826379489b9c44390c1c1621002205fe8ab97de3a08305967c9bf66d19a8426bd0d97d744639ab220a03ca8b5ef78", - "id": "d0361b035f314a248020f955eff949af0e979a41cc6b420683fc76f9391f598f" - }, - "serialized": "ff02170100000008000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19280969800000000002174686973206973206120746f70207365637265742076656e646f72206669656c6400c2eb0b000000000f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454012853415e170995750207ecaf0ccf251c1265b92ad84f553662304402206b83b7976c08bbc1f67a17d5481f498bdadd761826379489b9c44390c1c1621002205fe8ab97de3a08305967c9bf66d19a8426bd0d97d744639ab220a03ca8b5ef78" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/htlc-refund-multiSign.json b/src/test/resources/transactions/v2-ecdsa/htlc-refund-multiSign.json deleted file mode 100644 index f36eb19c..00000000 --- a/src/test/resources/transactions/v2-ecdsa/htlc-refund-multiSign.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 10, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "0", - "amount": "0", - "asset": { - "refund": { - "lockTransactionId": "943c220691e711c39c79d437ce185748a0018940e1a4144293af9d05627d2eb4" - } - }, - "signature": "3044022039b189def165ca903805e35f0fa8d0b5820861227d677909acb1650698a63415022020a124f535f92100cd8233f9b5e01eebda72b59c858600934f586fc7ee236574", - "id": "c8cf015e1566d9d63236e70c12988f6f13161f90d30ff5120ee62e37484034e3" - }, - "serialized": "ff0217010000000a000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192000000000000000000943c220691e711c39c79d437ce185748a0018940e1a4144293af9d05627d2eb43044022039b189def165ca903805e35f0fa8d0b5820861227d677909acb1650698a63415022020a124f535f92100cd8233f9b5e01eebda72b59c858600934f586fc7ee236574" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/ipfs-multiSign.json b/src/test/resources/transactions/v2-ecdsa/ipfs-multiSign.json deleted file mode 100644 index 27747208..00000000 --- a/src/test/resources/transactions/v2-ecdsa/ipfs-multiSign.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 5, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "500000000", - "amount": "0", - "asset": { - "ipfs": "QmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w" - }, - "signature": "3045022100e7d20c81b32e7a30fb741ba76fc823b667f38389b0a19d5e0a5779029843b792022050133f52000dc4327548c6f757f6ab2386f080d0fada8902de3d1372a2a9ff92", - "id": "b38f24116758b9b2fdb1f80b5ce02044af640f77d552080768942f9a9cfa2a88" - }, - "serialized": "ff02170100000005000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed1920065cd1d000000000012202853f0f11ab91d73b73a2a86606103f45dd469ad2e89ec6f9a25febe8758d3fe3045022100e7d20c81b32e7a30fb741ba76fc823b667f38389b0a19d5e0a5779029843b792022050133f52000dc4327548c6f757f6ab2386f080d0fada8902de3d1372a2a9ff92" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/multi-payment-multiSign.json b/src/test/resources/transactions/v2-ecdsa/multi-payment-multiSign.json deleted file mode 100644 index 811601d1..00000000 --- a/src/test/resources/transactions/v2-ecdsa/multi-payment-multiSign.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 6, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "10000000", - "amount": "0", - "asset": { - "payments": [ - { - "amount": "1", - "recipientId": "AHXtmB84sTZ9Zd35h9Y1vfFvPE2Xzqj8ri" - }, - { - "amount": "2", - "recipientId": "AZFEPTWnn2Sn8wDZgCRF8ohwKkrmk2AZi1" - } - ] - }, - "signature": "3044022068ecfe918717a0890ae0480045d526a7f14f163377e5e6dc4ce3bdd70c20cf750220261eaacb731cf386d5439e651fb2068ab59cb9ea2503d4a522f2da299870b3ae", - "id": "df4759a599ec78ac1cfb19ded5985312266dd009610eee5e71d55e69076c7d35" - }, - "serialized": "ff02170100000006000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed1928096980000000000000200010000000000000017134b5be4b327ddf9c2bb47fec8a1a44189e90f74020000000000000017bfa6aec83cf1bd03a0cab9f35c85ff51a3e9f0413044022068ecfe918717a0890ae0480045d526a7f14f163377e5e6dc4ce3bdd70c20cf750220261eaacb731cf386d5439e651fb2068ab59cb9ea2503d4a522f2da299870b3ae" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/multi-payment-with-vendor-field-multiSign.json b/src/test/resources/transactions/v2-ecdsa/multi-payment-with-vendor-field-multiSign.json deleted file mode 100644 index a0138200..00000000 --- a/src/test/resources/transactions/v2-ecdsa/multi-payment-with-vendor-field-multiSign.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 6, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "10000000", - "amount": "0", - "vendorField": "this is a top secret vendor field", - "asset": { - "payments": [ - { - "amount": "1", - "recipientId": "AHXtmB84sTZ9Zd35h9Y1vfFvPE2Xzqj8ri" - }, - { - "amount": "2", - "recipientId": "AZFEPTWnn2Sn8wDZgCRF8ohwKkrmk2AZi1" - } - ] - }, - "signature": "304402205d6a667239481f9306f37b35976626a39993b1088ee8ff2dee638905590c9508022040aa06bce7d20146c179d1106f29a821aa7278816e1f77f325e02caec3129565", - "id": "7bd4861b168d903500ecf15503804c9625f0eb0d86d350e3f0b73765f6ce2c7c" - }, - "serialized": "ff02170100000006000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19280969800000000002174686973206973206120746f70207365637265742076656e646f72206669656c640200010000000000000017134b5be4b327ddf9c2bb47fec8a1a44189e90f74020000000000000017bfa6aec83cf1bd03a0cab9f35c85ff51a3e9f041304402205d6a667239481f9306f37b35976626a39993b1088ee8ff2dee638905590c9508022040aa06bce7d20146c179d1106f29a821aa7278816e1f77f325e02caec3129565" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/transfer-multiSign.json b/src/test/resources/transactions/v2-ecdsa/transfer-multiSign.json deleted file mode 100644 index 19a6a8bb..00000000 --- a/src/test/resources/transactions/v2-ecdsa/transfer-multiSign.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 0, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "10000000", - "amount": "200000000", - "expiration": 0, - "recipientId": "AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC", - "signature": "3045022100af4741f03fdc64f0d6ed1dc69ecc77a000532ec1e3e30b9eb72d74eec404b25a0220437850da2e15b672e7ce55277b716770b99b3db995921cd2c69debafbcf22170", - "id": "9b038513f4dd77507da8a71d0204e491324d49f4598fe41f6c6985baae7d3517" - }, - "serialized": "ff02170100000000000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19280969800000000000000c2eb0b0000000000000000170995750207ecaf0ccf251c1265b92ad84f5536623045022100af4741f03fdc64f0d6ed1dc69ecc77a000532ec1e3e30b9eb72d74eec404b25a0220437850da2e15b672e7ce55277b716770b99b3db995921cd2c69debafbcf22170" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/transfer-with-vendor-field-multiSign.json b/src/test/resources/transactions/v2-ecdsa/transfer-with-vendor-field-multiSign.json deleted file mode 100644 index 27a9e3ab..00000000 --- a/src/test/resources/transactions/v2-ecdsa/transfer-with-vendor-field-multiSign.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 0, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "10000000", - "amount": "200000000", - "vendorField": "this is a top secret vendor field", - "expiration": 0, - "recipientId": "AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC", - "signature": "3045022100ef3a6127cfc4336be5f92c6133ea46d180eb90a526d7de2359f1f39ba4624ee30220718f4d2f2edb62a44d14a1c661d08d7454b55ecbe66160d0dfd7dd06e7b343a8", - "id": "0ad296322bfb656490b2d7a5dfc1fd88f840d412c4c8467ddba9890134647659" - }, - "serialized": "ff02170100000000000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19280969800000000002174686973206973206120746f70207365637265742076656e646f72206669656c6400c2eb0b0000000000000000170995750207ecaf0ccf251c1265b92ad84f5536623045022100ef3a6127cfc4336be5f92c6133ea46d180eb90a526d7de2359f1f39ba4624ee30220718f4d2f2edb62a44d14a1c661d08d7454b55ecbe66160d0dfd7dd06e7b343a8" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/unvote-multiSign.json b/src/test/resources/transactions/v2-ecdsa/unvote-multiSign.json deleted file mode 100644 index 251ab2af..00000000 --- a/src/test/resources/transactions/v2-ecdsa/unvote-multiSign.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 3, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "100000000", - "amount": "0", - "asset": { - "votes": [ - "-022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d" - ] - }, - "signature": "3045022100b3d67da287f35bb4f5ae28239cef8b5e82581f8030fe374c0ed86223d66b11bb02200a1ef45b603f70265a7437411565d9d577265452250bf279477f05b09feb5776", - "id": "cbfcca4f96dece8446c355052eb0aab2af82a526c0e4412140b865bc6336fc0e" - }, - "serialized": "ff02170100000003000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19200e1f50500000000000100022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d3045022100b3d67da287f35bb4f5ae28239cef8b5e82581f8030fe374c0ed86223d66b11bb02200a1ef45b603f70265a7437411565d9d577265452250bf279477f05b09feb5776" -} \ No newline at end of file diff --git a/src/test/resources/transactions/v2-ecdsa/vote-multiSign.json b/src/test/resources/transactions/v2-ecdsa/vote-multiSign.json deleted file mode 100644 index dd68ea89..00000000 --- a/src/test/resources/transactions/v2-ecdsa/vote-multiSign.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "data": { - "version": 2, - "network": 23, - "typeGroup": 1, - "type": 3, - "nonce": "1", - "senderPublicKey": "034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192", - "fee": "100000000", - "amount": "0", - "asset": { - "votes": [ - "+022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d" - ] - }, - "signature": "304402206a7a9baa573ab08bb4220450ace0d73ac9c768ef38b07a82ca19b2e2f11d0b550220665938431da66ad0b49e2267d65b220c59a35e1fea50083d45560a544f077eb6", - "id": "b8dce941db9d3b04a7afd142fc26e40ecc73f2865fbc84597dca9b907f9791f6" - }, - "serialized": "ff02170100000003000100000000000000034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed19200e1f50500000000000101022cca9529ec97a772156c152a00aad155ee6708243e65c9d211a589cb5d43234d304402206a7a9baa573ab08bb4220450ace0d73ac9c768ef38b07a82ca19b2e2f11d0b550220665938431da66ad0b49e2267d65b220c59a35e1fea50083d45560a544f077eb6" -} \ No newline at end of file