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();
}
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);
}
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);
}
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;
}
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;
}
Aggregations