Search in sources :

Example 1 with TransferTransactionFactory

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

the class TransactionServiceIntegrationTest method transferUsingAliasesAggregate.

private AggregateTransaction transferUsingAliasesAggregate(Account sender, RepositoryType type, String mosaicAlias, String recipientAlias, BigInteger amount) {
    NamespaceId recipientNamespace = NamespaceId.createFromName(recipientAlias);
    NamespaceId mosaicNamespace = NamespaceId.createFromName(mosaicAlias);
    System.out.println("Sending " + amount + " Mosaic to: " + mosaicAlias);
    TransferTransactionFactory factory = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipientNamespace, Collections.singletonList(new Mosaic(mosaicNamespace, amount))).message(new PlainMessage("E2ETest:TransactionServiceIntegrationTest"));
    factory.maxFee(maxFee);
    TransferTransaction transferTransaction = factory.build();
    Assertions.assertTrue(transferTransaction.getMosaics().get(0).getId() instanceof NamespaceId);
    Assertions.assertTrue(transferTransaction.getRecipient() instanceof NamespaceId);
    Pair<TransferTransaction, AggregateTransaction> pair = announceAggregateAndValidate(type, transferTransaction, sender);
    TransferTransaction processedTransferTransaction = pair.getLeft();
    Assertions.assertEquals(amount, processedTransferTransaction.getMosaics().get(0).getAmount());
    System.out.println(toJson(processedTransferTransaction));
    Assertions.assertTrue(processedTransferTransaction.getMosaics().get(0).getId() instanceof NamespaceId);
    Assertions.assertTrue(processedTransferTransaction.getRecipient() instanceof NamespaceId);
    return pair.getRight();
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic)

Example 2 with TransferTransactionFactory

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

the class HashLockTransactionIntegrationTest method standaloneLockFundsTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void standaloneLockFundsTransaction(RepositoryType type) {
    BigInteger duration = BigInteger.valueOf(10000);
    TransferTransactionFactory factory = TransferTransactionFactory.create(getNetworkType(), getDeadline(), account.getAddress(), Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("E2ETest:standaloneLockFundsTransaction"));
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(factory.build().toAggregate(account.getPublicAccount()))).maxFee(maxFee).build();
    SignedTransaction signedTransaction = this.account.sign(aggregateTransaction, getGenerationHash());
    HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), duration, signedTransaction).maxFee(maxFee).build();
    announceAndValidate(type, this.account, hashLockTransaction);
    announceAndValidate(type, this.account, aggregateTransaction);
}
Also used : HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with TransferTransactionFactory

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

the class HashLockTransactionIntegrationTest method aggregateLockFundsTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void aggregateLockFundsTransaction(RepositoryType type) {
    BigInteger duration = BigInteger.valueOf(1000);
    TransferTransactionFactory factory = TransferTransactionFactory.create(getNetworkType(), getDeadline(), this.account.getAddress(), Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("E2ETest:standaloneLockFundsTransaction"));
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(factory.build().toAggregate(account.getPublicAccount()))).maxFee(maxFee).build();
    SignedTransaction signedTransaction = this.account.sign(aggregateTransaction, getGenerationHash());
    HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), duration, signedTransaction).maxFee(maxFee).build();
    announceAggregateAndValidate(type, hashLockTransaction, this.account);
    announceAndValidate(type, this.account, aggregateTransaction);
}
Also used : HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with TransferTransactionFactory

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

the class TransferTransactionMapper method createFactory.

@Override
protected TransactionFactory<TransferTransaction> createFactory(NetworkType networkType, Deadline deadline, TransferTransactionDTO transaction) {
    List<Mosaic> mosaics = new ArrayList<>();
    if (transaction.getMosaics() != null) {
        mosaics = transaction.getMosaics().stream().map(mosaic -> new Mosaic(toUnresolvedMosaicId(mosaic.getId()), mosaic.getAmount())).collect(Collectors.toList());
    }
    TransferTransactionFactory transferTransactionFactory = TransferTransactionFactory.create(networkType, deadline, MapperUtils.toUnresolvedAddress(transaction.getRecipientAddress()), mosaics);
    Message.createFromHexPayload(transaction.getMessage()).ifPresent(transferTransactionFactory::message);
    return transferTransactionFactory;
}
Also used : TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) ArrayList(java.util.ArrayList) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) UnresolvedMosaic(io.nem.symbol.sdk.openapi.okhttp_gson.model.UnresolvedMosaic)

Example 5 with TransferTransactionFactory

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

the class TransferTransactionMapper method createFactory.

@Override
protected TransactionFactory<TransferTransaction> createFactory(NetworkType networkType, Deadline deadline, TransferTransactionDTO transaction) {
    List<Mosaic> mosaics = new ArrayList<>();
    if (transaction.getMosaics() != null) {
        mosaics = transaction.getMosaics().stream().map(mosaic -> new Mosaic(toUnresolvedMosaicId(mosaic.getId()), mosaic.getAmount())).collect(Collectors.toList());
    }
    TransferTransactionFactory transferTransactionFactory = TransferTransactionFactory.create(networkType, deadline, MapperUtils.toUnresolvedAddress(transaction.getRecipientAddress()), mosaics);
    Message.createFromHexPayload(transaction.getMessage()).ifPresent(transferTransactionFactory::message);
    return transferTransactionFactory;
}
Also used : TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) ArrayList(java.util.ArrayList) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) UnresolvedMosaic(io.nem.symbol.sdk.openapi.vertx.model.UnresolvedMosaic)

Aggregations

TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)7 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)4 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)4 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)3 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)3 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)2 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)2 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 EnumSource (org.junit.jupiter.params.provider.EnumSource)2 UnresolvedMosaic (io.nem.symbol.sdk.openapi.okhttp_gson.model.UnresolvedMosaic)1 UnresolvedMosaic (io.nem.symbol.sdk.openapi.vertx.model.UnresolvedMosaic)1