use of io.nem.symbol.sdk.api.Listener in project nem2-sdk-java by nemtech.
the class MultisignIntegrationTest method shouldReturnCosignatureAddedViaListener2.
@Disabled
@ParameterizedTest
@EnumSource(RepositoryType.class)
void shouldReturnCosignatureAddedViaListener2(RepositoryType type) {
Listener listener = getListener(type);
RepositoryFactory repositoryFactory = getRepositoryFactory(type);
TransactionRepository transactionRepository = repositoryFactory.createTransactionRepository();
SignedTransaction signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.getAddress());
Object finalObject = get(createHashLockTransactionAndAnnounce(type, signedAggregatedTx, cosignAccount1).flatMap(t -> {
System.out.println("hash lock finished");
TransactionServiceImpl transactionService = new TransactionServiceImpl(getRepositoryFactory(type));
return transactionService.announceAggregateBonded(listener, signedAggregatedTx).flatMap(a -> {
System.out.println("Aggregate bonded finished");
return repositoryFactory.createTransactionRepository().search(new TransactionSearchCriteria(TransactionGroup.PARTIAL).signerPublicKey(cosignAccount1.getPublicAccount().getPublicKey())).flatMap((page) -> {
List<Transaction> transactions = page.getData();
System.out.println("partialTransactions " + transactions.size());
AggregateTransaction transactionToCosign = (AggregateTransaction) transactions.get(0);
CosignatureTransaction cosignatureTransaction = CosignatureTransaction.create(transactionToCosign);
CosignatureSignedTransaction cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction);
return transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction).flatMap(r -> {
System.out.println("announceAggregateBondedCosignature " + r);
return listener.cosignatureAdded(cosignAccount1.getAddress());
});
});
});
}));
System.out.println(finalObject.getClass());
Assertions.assertNull(finalObject);
}
use of io.nem.symbol.sdk.api.Listener 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.api.Listener in project nem2-sdk-java by nemtech.
the class TransferTransactionIntegrationTest method basicTransfer.
private List<String> basicTransfer(RepositoryType type, UnresolvedAddress recipient, String s, int i, List<String> expected, boolean includeAliases, UnresolvedAddress... listenTo) throws InterruptedException, ExecutionException {
List<String> messages = new ArrayList<>();
Listener listener = listen(type, messages, includeAliases, listenTo);
sleep(1000);
try {
String message = s;
Currency networkCurrency = getNetworkCurrency();
Mosaic mosaic = new Mosaic(networkCurrency.getNamespaceId().get(), BigInteger.valueOf(i));
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(mosaic)).message(new PlainMessage(message)).maxFee(maxFee).build();
TransferTransaction processed = announceAggregateAndValidate(type, transferTransaction, signerAccount).getKey();
Assertions.assertEquals(message, processed.getMessage().get().getText());
sleep(1000);
Assertions.assertEquals(expected, messages);
return messages;
} finally {
listener.close();
}
}
use of io.nem.symbol.sdk.api.Listener in project nem2-sdk-java by nemtech.
the class TestHelper method createListener.
private Listener createListener(RepositoryType type) {
Listener listener = getRepositoryFactory(type).createListener();
get(listener.open());
return listener;
}
use of io.nem.symbol.sdk.api.Listener in project nem2-sdk-java by nemtech.
the class ListenerIntegrationTest method getAllMultisigAddressesAndAliasesWhenBasic.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void getAllMultisigAddressesAndAliasesWhenBasic(RepositoryType type) {
Account testAccount = this.helper().getTestAccount(type).getKey();
Set<NamespaceId> cosignatoryAccount1aliases = get(getRepositoryFactory(type).createNamespaceRepository().getAccountsNames(Collections.singletonList(testAccount.getAddress()))).stream().flatMap(a -> a.getNames().stream().map(NamespaceName::getNamespaceId)).collect(Collectors.toSet());
Listener listener = getRepositoryFactory(type).createListener();
final Set<UnresolvedAddress> unresolvedAddresses = get(listener.getAllMultisigAddressesAndAliases(testAccount.getAddress()));
final Set<UnresolvedAddress> expectedAddresees = Sets.newSet(testAccount.getAddress());
expectedAddresees.addAll(cosignatoryAccount1aliases);
Assertions.assertEquals(expectedAddresees, unresolvedAddresses);
}
Aggregations