use of io.nem.symbol.sdk.api.TransactionService in project nem2-sdk-java by nemtech.
the class ListenerIntegrationTest method shouldReturnAggregateBondedAddedTransactionViaListener.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void shouldReturnAggregateBondedAddedTransactionViaListener(RepositoryType type) {
Listener listener = getListener(type);
RepositoryFactory repositoryFactory = getRepositoryFactory(type);
TransactionService transactionService = new TransactionServiceImpl(repositoryFactory);
Pair<SignedTransaction, SignedTransaction> pair = this.createAggregateBondedTransaction(type);
System.out.println("Announcing HashLock transaction " + pair.getRight().getHash());
get(transactionService.announce(listener, pair.getRight()));
SignedTransaction signedTransaction = pair.getLeft();
System.out.println("Announcing Aggregate transaction " + signedTransaction.getHash());
AggregateTransaction aggregateTransaction = get(transactionService.announceAggregateBonded(listener, signedTransaction).take(1));
assertEquals(signedTransaction.getHash(), aggregateTransaction.getTransactionInfo().get().getHash().get());
}
use of io.nem.symbol.sdk.api.TransactionService 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.TransactionService in project nem2-sdk-java by nemtech.
the class CreatingAnEscrowContractWithAggregateBondedTransactionIntegrationTest method executeTransfer.
@Test
@Disabled
void executeTransfer() {
Account ticketDistributorAccount = this.config().getTestAccount();
Account aliceAccount = this.config().getTestAccount2();
RepositoryType type = DEFAULT_REPOSITORY_TYPE;
MosaicId mosaicId = createMosaic(ticketDistributorAccount, type, BigInteger.ZERO, null);
TransferTransaction aliceToTicketDistributorTx = TransferTransactionFactory.create(getNetworkType(), getDeadline(), ticketDistributorAccount.getAddress(), Collections.singletonList(getNetworkCurrency().createRelative(BigInteger.valueOf(100)))).message(new PlainMessage("send 100 cat.currency to distributor")).maxFee(maxFee).build();
TransferTransaction ticketDistributorToAliceTx = TransferTransactionFactory.create(getNetworkType(), getDeadline(), aliceAccount.getAddress(), Collections.singletonList(new Mosaic(mosaicId, BigInteger.ONE))).message(new PlainMessage("send 1 museum ticket to alice")).maxFee(maxFee).build();
/* end block 01 */
/* start block 02 */
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Arrays.asList(aliceToTicketDistributorTx.toAggregate(aliceAccount.getPublicAccount()), ticketDistributorToAliceTx.toAggregate(ticketDistributorAccount.getPublicAccount()))).maxFee(maxFee).build();
String networkGenerationHash = getGenerationHash();
SignedTransaction signedTransaction = aliceAccount.sign(aggregateTransaction, networkGenerationHash);
System.out.println("Aggregate Transaction Hash: " + signedTransaction.getHash());
/* end block 02 */
/* start block 03 */
HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.TEN), BigInteger.valueOf(480), signedTransaction).maxFee(maxFee).build();
SignedTransaction signedHashLockTransaction = aliceAccount.sign(hashLockTransaction, networkGenerationHash);
System.out.println("Hash Transaction Hash: " + hashLockTransaction.getHash());
TransactionService transactionService = getTransactionService(type);
Transaction transaction = get(transactionService.announceHashLockAggregateBonded(getListener(type), signedHashLockTransaction, signedTransaction));
Assertions.assertNotNull(transaction);
}
use of io.nem.symbol.sdk.api.TransactionService in project nem2-sdk-java by nemtech.
the class ListenerIntegrationTest method shouldReturnCosignatureAddedViaListener.
@ParameterizedTest
@EnumSource(RepositoryType.class)
@Disabled
void shouldReturnCosignatureAddedViaListener(RepositoryType type) {
Listener listener = getListener(type);
RepositoryFactory repositoryFactory = getRepositoryFactory(type);
TransactionService transactionService = new TransactionServiceImpl(repositoryFactory);
Pair<SignedTransaction, SignedTransaction> pair = this.createAggregateBondedTransaction(type);
System.out.println("Announcing HashLock transaction " + pair.getRight().getHash());
get(transactionService.announce(listener, pair.getRight()));
SignedTransaction signedTransaction = pair.getLeft();
AggregateTransaction announcedTransaction = get(transactionService.announceAggregateBonded(listener, signedTransaction));
assertEquals(signedTransaction.getHash(), announcedTransaction.getTransactionInfo().get().getHash().get());
TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).transactionTypes(Collections.singletonList(TransactionType.AGGREGATE_BONDED)).signerPublicKey(this.cosignatoryAccount.getPublicAccount().getPublicKey()))).getData();
AggregateTransaction transactionToCosign = (AggregateTransaction) transactions.get(0);
this.announceCosignatureTransaction(transactionToCosign, type);
CosignatureSignedTransaction cosignatureSignedTransaction = get(listener.cosignatureAdded(this.cosignatoryAccount.getAddress()).take(1));
assertEquals(cosignatureSignedTransaction.getSigner(), this.cosignatoryAccount2.getPublicAccount());
}
use of io.nem.symbol.sdk.api.TransactionService in project nem2-sdk-java by nemtech.
the class ListenerIntegrationTest method shouldReturnAggregateBondedRemovedTransactionViaListener.
@ParameterizedTest
@EnumSource(RepositoryType.class)
@Disabled
void shouldReturnAggregateBondedRemovedTransactionViaListener(RepositoryType type) {
Listener listener = getListener(type);
RepositoryFactory repositoryFactory = getRepositoryFactory(type);
TransactionService transactionService = new TransactionServiceImpl(repositoryFactory);
Pair<SignedTransaction, SignedTransaction> pair = this.createAggregateBondedTransaction(type);
System.out.println("Announcing HashLock transaction " + pair.getRight().getHash());
get(transactionService.announce(listener, pair.getRight()));
SignedTransaction signedTransaction = pair.getLeft();
System.out.println("Announcing Aggregate transaction " + signedTransaction.getHash());
get(transactionService.announceAggregateBonded(listener, signedTransaction).take(1));
String transactionHash = get(listener.aggregateBondedRemoved(this.account.getAddress()).take(1));
assertEquals(signedTransaction.getHash(), transactionHash);
}
Aggregations