use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.
the class OkHttpAggregateTransactionTest method createAAggregateTransactionViaStaticConstructor.
@Test
void createAAggregateTransactionViaStaticConstructor() {
Duration epochAdjustment = Duration.ofSeconds(100);
Address recipient = Address.generateRandom(NetworkType.MIJIN_TEST);
TransferTransaction transferTx = TransferTransactionFactory.create(networkType, deadline, recipient, Collections.emptyList()).message(new PlainMessage("")).build();
AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, Deadline.create(epochAdjustment), Collections.singletonList(transferTx.toAggregate(new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", networkType)))).build();
assertEquals(networkType, aggregateTx.getNetworkType());
assertEquals(1, (int) aggregateTx.getVersion());
assertTrue(LocalDateTime.now().isBefore(aggregateTx.getDeadline().getLocalDateTime(epochAdjustment)));
assertEquals(BigInteger.valueOf(0), aggregateTx.getMaxFee());
assertEquals(1, aggregateTx.getInnerTransactions().size());
}
use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.
the class OkHttpAggregateTransactionTest method serialization.
@Test
@DisplayName("Serialization")
void serialization() {
Address address = Address.generateRandom(networkType);
TransferTransaction transferTx = TransferTransactionFactory.create(networkType, deadline, address, Collections.singletonList(createAbsolute(BigInteger.valueOf(10000000)))).message(new PlainMessage("")).build();
PublicAccount signer = Account.generateNewAccount(networkType).getPublicAccount();
AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, deadline, Collections.singletonList(transferTx.toAggregate(signer))).build();
byte[] actual = aggregateTx.serialize();
BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(actual);
assertEquals(signer, deserialized.getInnerTransactions().get(0).getSigner().get());
}
use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.
the class ListenerIntegrationTest method announceStandaloneTransferTransaction.
private SignedTransaction announceStandaloneTransferTransaction(RepositoryType type, Address recipient) {
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(10000L)))).message(new PlainMessage("test-message")).maxFee(maxFee).build();
SignedTransaction signedTransaction = this.account.sign(transferTransaction, getGenerationHash());
System.out.println("Announcing transaction " + signedTransaction.getHash());
get(getTransactionRepository(type).announce(signedTransaction));
System.out.println("Transaction " + signedTransaction.getHash() + " Announced");
return signedTransaction;
}
use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.
the class CreatingAnEscrowContractWithAggregateBondedTransactionIntegrationTest method executeTransfer.
@Test
@Disabled
void executeTransfer() {
Account ticketDistributorAccount = this.config().getTestAccount();
Account aliceAccount = this.config().getTestAccount2();
RepositoryType type = DEFAULT_REPOSITORY_TYPE;
MosaicId mosaicId = createMosaic(ticketDistributorAccount, type, BigInteger.ZERO, null);
TransferTransaction aliceToTicketDistributorTx = TransferTransactionFactory.create(getNetworkType(), getDeadline(), ticketDistributorAccount.getAddress(), Collections.singletonList(getNetworkCurrency().createRelative(BigInteger.valueOf(100)))).message(new PlainMessage("send 100 cat.currency to distributor")).maxFee(maxFee).build();
TransferTransaction ticketDistributorToAliceTx = TransferTransactionFactory.create(getNetworkType(), getDeadline(), aliceAccount.getAddress(), Collections.singletonList(new Mosaic(mosaicId, BigInteger.ONE))).message(new PlainMessage("send 1 museum ticket to alice")).maxFee(maxFee).build();
/* end block 01 */
/* start block 02 */
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Arrays.asList(aliceToTicketDistributorTx.toAggregate(aliceAccount.getPublicAccount()), ticketDistributorToAliceTx.toAggregate(ticketDistributorAccount.getPublicAccount()))).maxFee(maxFee).build();
String networkGenerationHash = getGenerationHash();
SignedTransaction signedTransaction = aliceAccount.sign(aggregateTransaction, networkGenerationHash);
System.out.println("Aggregate Transaction Hash: " + signedTransaction.getHash());
/* end block 02 */
/* start block 03 */
HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.TEN), BigInteger.valueOf(480), signedTransaction).maxFee(maxFee).build();
SignedTransaction signedHashLockTransaction = aliceAccount.sign(hashLockTransaction, networkGenerationHash);
System.out.println("Hash Transaction Hash: " + hashLockTransaction.getHash());
TransactionService transactionService = getTransactionService(type);
Transaction transaction = get(transactionService.announceHashLockAggregateBonded(getListener(type), signedHashLockTransaction, signedTransaction));
Assertions.assertNotNull(transaction);
}
use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.
the class ListenerStatusIntegrationTest method sendTransactionsNewListener.
@Test
void sendTransactionsNewListener() throws ExecutionException, InterruptedException {
RepositoryType type = DEFAULT_REPOSITORY_TYPE;
Account account1 = config().getNemesisAccount1();
Account account2 = Account.generateNewAccount(getNetworkType());
Account account3 = Account.generateNewAccount(getNetworkType());
createListener(type).unconfirmedRemoved(account1.getAddress()).subscribe(a -> {
System.out.println(">>>> account 1 " + a);
});
createListener(type).unconfirmedRemoved(account2.getAddress()).subscribe(a -> {
System.out.println(">>>> account 2 " + a);
});
createListener(type).unconfirmedRemoved(account3.getAddress()).subscribe(a -> {
System.out.println(">>>> account 3 " + a);
});
// IT prints:
// >>>> account 1
// B742A00E5F7D8381F78EBE8CE47023C6298FB1802CDB3861CA0C05286DE0EE63
// >>>> account 2
// B742A00E5F7D8381F78EBE8CE47023C6298FB1802CDB3861CA0C05286DE0EE63
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), account2.getAddress(), Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("test-message")).maxFee(maxFee).build();
announceAndValidate(type, account1, transferTransaction);
sleep(1000);
}
Aggregations