use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.
the class TransactionRepositoryIntegrationTest method setup.
@BeforeAll
void setup() {
RepositoryType type = RepositoryType.VERTX;
TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
Address recipient = getRecipient();
String message = "someMessage";
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage(message)).maxFee(maxFee).build();
TransferTransaction processed = announceAndValidate(type, config().getDefaultAccount(), transferTransaction);
Assertions.assertEquals(message, processed.getMessage().get().getText());
PublicAccount account = config().getDefaultAccount().getPublicAccount();
List<Transaction> allTransactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).order(OrderBy.DESC).signerPublicKey(account.getPublicKey()))).getData();
List<Transaction> transactions = allTransactions.stream().filter(t -> t.getType() == TransactionType.TRANSFER).collect(Collectors.toList());
Assertions.assertTrue(allTransactions.size() > 0);
Assertions.assertTrue(transactions.size() > 0);
transactionHash = transactions.get(0).getTransactionInfo().get().getHash().get();
}
use of io.nem.symbol.sdk.model.transaction.TransferTransaction 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.TransferTransaction in project nem2-sdk-java by nemtech.
the class ListenerIntegrationTest method createAggregateBondedTransaction.
private Pair<SignedTransaction, SignedTransaction> createAggregateBondedTransaction(RepositoryType type) {
helper().sendMosaicFromNemesis(type, this.cosignatoryAccount.getAddress(), false);
helper().sendMosaicFromNemesis(type, this.cosignatoryAccount2.getAddress(), false);
helper().sendMosaicFromNemesis(type, this.multisigAccount.getAddress(), false);
helper().createMultisigAccountBonded(type, this.multisigAccount, this.cosignatoryAccount, this.cosignatoryAccount2);
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), Account.generateNewAccount(getNetworkType()).getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).maxFee(maxFee).build();
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(transferTransaction.toAggregate(this.multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction aggregateSignedTransaction = this.cosignatoryAccount.sign(aggregateTransaction, getGenerationHash());
HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(100), aggregateSignedTransaction).maxFee(maxFee).build();
SignedTransaction signedHashLockTransaction = hashLockTransaction.signWith(this.cosignatoryAccount, getGenerationHash());
return Pair.of(aggregateSignedTransaction, signedHashLockTransaction);
}
use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.
the class ListenerStatusIntegrationTest method sendTransactionsReusingListener.
@Test
void sendTransactionsReusingListener() throws ExecutionException, InterruptedException {
RepositoryType type = DEFAULT_REPOSITORY_TYPE;
Account account1 = config().getNemesisAccount1();
Account account2 = Account.generateNewAccount(getNetworkType());
Account account3 = Account.generateNewAccount(getNetworkType());
Listener listener = createListener(type);
listener.unconfirmedRemoved(account1.getAddress()).subscribe(a -> {
System.out.println(">>>> account 1 " + a);
});
listener.unconfirmedRemoved(account2.getAddress()).subscribe(a -> {
System.out.println(">>>> account 2 " + a);
});
listener.unconfirmedRemoved(account3.getAddress()).subscribe(a -> {
System.out.println(">>>> account 3 " + a);
});
// IT PRINTS:
// >>>> account 1
// 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
// >>>> account 2
// 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
// >>>> account 3
// 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
// >>>> account 1
// 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
// >>>> account 2
// 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
// >>>> account 3
// 94BE61F8FA091319A3564D843468ABD8E51034F7CDF132A74BBA2A7465E27C7D
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);
}
use of io.nem.symbol.sdk.model.transaction.TransferTransaction in project nem2-sdk-java by nemtech.
the class OkHttpAggregateTransactionTest method shouldCreateAggregateTransactionAndSignWithMultipleCosignatories.
@Test
void shouldCreateAggregateTransactionAndSignWithMultipleCosignatories() {
Address address = Address.generateRandom(networkType);
TransferTransaction transferTx = TransferTransactionFactory.create(networkType, deadline, address, Collections.emptyList()).message(new PlainMessage("test-message")).build();
AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, deadline, Collections.singletonList(transferTx.toAggregate(new PublicAccount("B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D", networkType)))).build();
Account cosignatoryAccount = Account.generateNewAccount(this.networkType);
Account cosignatoryAccount2 = Account.generateNewAccount(this.networkType);
Account cosignatoryAccount3 = Account.generateNewAccount(this.networkType);
SignedTransaction signedTransaction = cosignatoryAccount.signTransactionWithCosignatories(aggregateTx, Arrays.asList(cosignatoryAccount2, cosignatoryAccount3), generationHash);
BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
Assertions.assertEquals(2, deserialized.getCosignatures().size());
Assertions.assertEquals(cosignatoryAccount2.getPublicAccount(), deserialized.getCosignatures().get(0).getSigner());
Assertions.assertEquals(cosignatoryAccount3.getPublicAccount(), deserialized.getCosignatures().get(1).getSigner());
}
Aggregations