use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.
the class MultisignIntegrationTest method createMultisigAccount.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void createMultisigAccount(RepositoryType type) {
boolean multisigAccountExist = get(getRepositoryFactory(type).createMultisigRepository().getMultisigAccountInfo(multisigAccount.getAddress()).map(s -> true).onErrorReturnItem(false));
if (multisigAccountExist) {
System.out.println("Multisign account " + multisigAccount.getAddress().plain() + " already exist");
return;
}
MultisigAccountModificationTransaction modifyMultisigAccountTransaction = MultisigAccountModificationTransactionFactory.create(getNetworkType(), getDeadline(), (byte) 2, (byte) 1, Arrays.asList(cosignAccount1.getAddress(), cosignAccount2.getAddress(), cosignAccount3.getAddress()), Collections.emptyList()).maxFee(maxFee).build();
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(modifyMultisigAccountTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction signedTransaction = aggregateTransaction.signTransactionWithCosigners(multisigAccount, Arrays.asList(cosignAccount1, cosignAccount2, cosignAccount3), getGenerationHash());
Transaction transaction = get(getTransactionService(type).announce(getListener(type), signedTransaction));
Assertions.assertNotNull(transaction);
}
use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.
the class TestnetTester method announceTransaction.
private static void announceTransaction(RepositoryFactory repositoryFactory, Account account, Transaction transaction) throws Exception {
TransactionService transactionService = new TransactionServiceImpl(repositoryFactory);
String generationHash = repositoryFactory.getGenerationHash().toFuture().get();
try (Listener listener = repositoryFactory.createListener()) {
listener.open().get();
SignedTransaction signedTransaction = account.sign(transaction, generationHash);
System.out.println(signedTransaction.getHash());
Transaction completedTransaction = transactionService.announce(listener, signedTransaction).toFuture().get();
System.out.println(completedTransaction.getTransactionInfo().get().getHash().get());
}
}
use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.
the class TransactionSearchRepositoryIntegrationTest method searchUnconfirmed.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchUnconfirmed(RepositoryType type) {
TransactionRepository transactionRepository = getTransactionRepository(type);
Address recipient = getRecipient();
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("")).maxFee(maxFee).build();
Account signer = config().getDefaultAccount();
SignedTransaction signedTransaction = transferTransaction.signWith(signer, getGenerationHash());
get(transactionRepository.announce(signedTransaction));
get(getListener(type).unconfirmedAdded(signer.getAddress(), signedTransaction.getHash()).take(1));
TransactionPaginationStreamer streamer = new TransactionPaginationStreamer(transactionRepository);
TransactionGroup group = TransactionGroup.UNCONFIRMED;
TransactionSearchCriteria criteria = new TransactionSearchCriteria(group);
criteria.transactionTypes(Collections.singletonList(TransactionType.TRANSFER));
List<Transaction> transactions = get(streamer.search(criteria).toList().toObservable());
transactions.forEach(b -> Assertions.assertEquals(TransactionType.TRANSFER, b.getType()));
Assertions.assertTrue(transactions.stream().filter(t -> t.getTransactionInfo().get().getHash().get().equals(signedTransaction.getHash())).findAny().isPresent());
helper.assertById(transactionRepository, group, transactions);
}
use of io.nem.symbol.sdk.model.transaction.SignedTransaction 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.SignedTransaction in project nem2-sdk-java by nemtech.
the class ListenerIntegrationTest method shouldReturnConfirmedTransactionAddressSignerViaListener.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void shouldReturnConfirmedTransactionAddressSignerViaListener(RepositoryType type) {
Listener listener = getListener(type);
SignedTransaction signedTransaction = this.announceStandaloneTransferTransaction(type, this.getRecipient());
Observable<Transaction> confirmed = listener.confirmed(this.account.getAddress(), signedTransaction.getHash());
Transaction transaction = get(confirmed.take(1));
assertEquals(signedTransaction.getHash(), transaction.getTransactionInfo().get().getHash().get());
}
Aggregations