Search in sources :

Example 46 with TransferTransaction

use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.

the class TransactionServiceIntegrationTest method testTransferCustomCurrencyFromAccount1UsingAggregate.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void testTransferCustomCurrencyFromAccount1UsingAggregate(RepositoryType type) {
    String mosaicAlias = ("testTransferCustomCurrencyFromAccount1UsingAggregate" + RandomUtils.nextInt(0, 10000)).toLowerCase();
    Account testAccount = helper().getTestAccount(type).getLeft();
    String recipientAlias = "testaccount" + RandomUtils.nextInt(0, 10000);
    MosaicId mosaicId = helper().createMosaic(testAccount, type, BigInteger.valueOf(10000), mosaicAlias);
    String aggregateTransactionHash = transferUsingAliasesAggregate(testAccount, type, mosaicAlias, recipientAlias, BigInteger.ONE).getTransactionInfo().get().getHash().get();
    List<Transaction> transactions = get(getTransactionService(type).resolveAliases(Collections.singletonList(aggregateTransactionHash)));
    Assertions.assertEquals(1, transactions.size());
    TransferTransaction resolvedTransaction = (TransferTransaction) ((AggregateTransaction) transactions.get(0)).getInnerTransactions().get(0);
    assertTransaction(mosaicId, resolvedTransaction, testAccount);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) 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) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 47 with TransferTransaction

use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.

the class TransactionSearchRepositoryIntegrationTest method searchEmbedded.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchEmbedded(RepositoryType type) {
    TransactionRepository transactionRepository = getTransactionRepository(type);
    TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
    TransactionGroup group = TransactionGroup.CONFIRMED;
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(group).embedded(true);
    List<Transaction> transactions = get(streamer.search(criteria).toList().toObservable());
    transactions.forEach(b -> {
        TransferTransaction transferTransaction = (TransferTransaction) b;
        Message message = transferTransaction.getMessage().orElse(PlainMessage.create("No Message!!"));
        Assertions.assertNotNull(message.getText());
    });
    Assertions.assertFalse(transactions.isEmpty());
}
Also used : SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) Message(io.nem.symbol.sdk.model.message.Message) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) TransactionPaginationStreamer(io.nem.symbol.sdk.api.TransactionPaginationStreamer) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 48 with TransferTransaction

use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.

the class TransactionSearchRepositoryIntegrationTest method searchTransactionType.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchTransactionType(RepositoryType type) {
    TransactionRepository transactionRepository = getTransactionRepository(type);
    TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
    TransactionGroup group = TransactionGroup.CONFIRMED;
    TransactionSearchCriteria criteria = new TransactionSearchCriteria(group).transactionTypes(Arrays.asList(TransactionType.TRANSFER));
    List<Transaction> transactions = get(streamer.search(criteria).toList().toObservable());
    transactions.forEach(b -> {
        TransferTransaction transferTransaction = (TransferTransaction) b;
        Message message = transferTransaction.getMessage().orElse(PlainMessage.create("No Message!!"));
        Assertions.assertNotNull(message.getText());
    });
    Assertions.assertFalse(transactions.isEmpty());
}
Also used : SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) Message(io.nem.symbol.sdk.model.message.Message) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) TransactionPaginationStreamer(io.nem.symbol.sdk.api.TransactionPaginationStreamer) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 with TransferTransaction

use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.

the class RepositoryFactoryConfigurationExamplesIntegrationTest method appDoSomeStuff.

public void appDoSomeStuff(RepositoryFactory repositoryFactory) throws ExecutionException, InterruptedException {
    // The application logic is exactly the same regardless of how the repository
    // factory was
    // set
    // Note: if rest is used, these values are cached form rest
    Currency currency = repositoryFactory.getNetworkCurrency().toFuture().get();
    String generationHash = repositoryFactory.getGenerationHash().toFuture().get();
    NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
    Account sender = Account.generateNewAccount(networkType);
    Account recipient = Account.generateNewAccount(networkType);
    Duration epochAdjustment = repositoryFactory.getEpochAdjustment().toFuture().get();
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, Deadline.create(epochAdjustment), recipient.getAddress(), Collections.singletonList(currency.createRelative(BigInteger.TEN))).message(new PlainMessage("")).build();
    SignedTransaction signedTransaction = transferTransaction.signWith(sender, generationHash);
// Announce or store somewhere....
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Currency(io.nem.symbol.sdk.model.mosaic.Currency) Duration(java.time.Duration) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction)

Example 50 with TransferTransaction

use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.

the class MultisigAccountOperationsIntegrationTest method cosignatureTransactionOnSign.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void cosignatureTransactionOnSign(RepositoryType type) {
    Account multisigAccount = helper().getMultisigAccount(type).getLeft();
    Account cosignatoryAccount = config().getCosignatoryAccount();
    Address recipient = getRecipient();
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("test-message")).maxFee(maxFee).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(transferTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
    SignedTransaction signedTransaction = cosignatoryAccount.sign(aggregateTransaction, getGenerationHash());
    TransactionFactory<HashLockTransaction> hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(100), signedTransaction).maxFee(maxFee);
    SignedTransaction signedHashLockTransaction = hashLockTransaction.build().signWith(cosignatoryAccount, getGenerationHash());
    AggregateTransaction finalTransaction = getTransactionOrFail(getTransactionService(type).announceHashLockAggregateBonded(getListener(type), signedHashLockTransaction, signedTransaction), aggregateTransaction);
    Assertions.assertNotNull(finalTransaction);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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