Search in sources :

Example 31 with TransferTransaction

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());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Duration(java.time.Duration) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Test(org.junit.jupiter.api.Test)

Example 32 with TransferTransaction

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());
}
Also used : BinarySerialization(io.nem.symbol.sdk.api.BinarySerialization) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 33 with TransferTransaction

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;
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)

Example 34 with TransferTransaction

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);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransactionService(io.nem.symbol.sdk.api.TransactionService) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 35 with TransferTransaction

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);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)63 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)48 Test (org.junit.jupiter.api.Test)37 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)35 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)31 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)28 Account (io.nem.symbol.sdk.model.account.Account)18 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 EnumSource (org.junit.jupiter.params.provider.EnumSource)14 Address (io.nem.symbol.sdk.model.account.Address)13 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)13 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)10 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)8 BigInteger (java.math.BigInteger)8 ArrayList (java.util.ArrayList)8 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)7 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)7 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)5 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)5