use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class TestHelper method announceAggregateAndValidate.
<T extends Transaction> Pair<T, AggregateTransaction> announceAggregateAndValidate(RepositoryType type, T transaction, Account signer, Account... cosigners) {
System.out.println("Announcing Aggregate Transaction: " + transaction.getType() + " signer " + signer.getAddress().plain() + " cosigners: " + Arrays.stream(cosigners).map(s -> s.getAddress().plain()).collect(Collectors.joining(", ")));
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(transaction.toAggregate(signer.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction signedTransaction = signer.signTransactionWithCosignatories(aggregateTransaction, Arrays.asList(cosigners), getGenerationHash());
if (transaction.getType() != TransactionType.AGGREGATE_COMPLETE) {
System.out.println("Announcing Transaction Transaction: " + transaction.getType() + " Address: " + signer.getAddress().plain() + " Public Key: " + signer.getPublicAccount().getPublicKey().toHex() + " hash " + signedTransaction.getHash());
}
TransactionService transactionService = new TransactionServiceImpl(getRepositoryFactory(type));
AggregateTransaction announcedAggregateTransaction = (AggregateTransaction) getTransactionOrFail(transactionService.announce(getListener(type), signedTransaction), transaction);
T announcedCorrectly = (T) announcedAggregateTransaction.getInnerTransactions().get(0);
System.out.println("Transaction completed, Transaction hash " + announcedAggregateTransaction.getTransactionInfo().get().getHash().get());
return Pair.of(announcedCorrectly, announcedAggregateTransaction);
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class TestHelper method setAddressAlias.
public NamespaceId setAddressAlias(RepositoryType type, Address address, String namespaceName) {
NamespaceId namespaceId = NamespaceId.createFromName(namespaceName);
if (isAlias(type, address, namespaceId)) {
System.out.println(namespaceName + " ADDRESS Alias for address " + address.plain() + " found, reusing it.");
return namespaceId;
}
System.out.println(namespaceName + " ADDRESS Alias not found, CREATING ADDRESS " + address.plain() + " ALIAS");
Account nemesisAccount = config().getNemesisAccount1();
System.out.println("Setting up namespace " + namespaceName);
NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, getDuration()).maxFee(maxFee).build();
NamespaceId rootNamespaceId = announceAggregateAndValidate(type, namespaceRegistrationTransaction, nemesisAccount).getLeft().getNamespaceId();
System.out.println("Setting account alias " + address.plain() + " alias: " + namespaceName);
AddressAliasTransaction aliasTransaction = AddressAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, address).maxFee(maxFee).build();
announceAggregateAndValidate(type, aliasTransaction, nemesisAccount);
int retry = 10;
while (!isAlias(type, address, namespaceId)) {
sleep(300);
retry--;
if (retry == 0) {
Assertions.fail("Could not create " + address.plain() + " alias: " + namespaceName);
}
}
return rootNamespaceId;
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class TestHelper method createMultisigAccountBonded.
public MultisigAccountInfo createMultisigAccountBonded(RepositoryType type, Account multisigAccount, Account... accounts) {
AccountRepository accountRepository = getRepositoryFactory(type).createAccountRepository();
MultisigRepository multisigRepository = getRepositoryFactory(type).createMultisigRepository();
AccountInfo accountInfo = get(accountRepository.getAccountInfo(multisigAccount.getAddress()));
System.out.println(getJsonHelper().print(accountInfo));
if (isMultisig(type, multisigAccount)) {
System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " already exist");
return get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
}
System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " does not exist. Creating");
System.out.println("Creating multisg account " + multisigAccount.getAddress().plain());
List<UnresolvedAddress> additions = Arrays.stream(accounts).map(Account::getAddress).collect(Collectors.toList());
MultisigAccountModificationTransaction convertIntoMultisigTransaction = MultisigAccountModificationTransactionFactory.create(getNetworkType(), getDeadline(), (byte) 1, (byte) 1, additions, Collections.emptyList()).maxFee(maxFee).build();
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(convertIntoMultisigTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction signedAggregateTransaction = aggregateTransaction.signTransactionWithCosigners(multisigAccount, Arrays.asList(accounts), getGenerationHash());
Mosaic hashAmount = getCurrency().createRelative(BigInteger.valueOf(10));
HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), hashAmount, BigInteger.valueOf(100), signedAggregateTransaction).maxFee(maxFee).build();
SignedTransaction signedHashLockTransaction = hashLockTransaction.signWith(multisigAccount, getGenerationHash());
getTransactionOrFail(getTransactionService(type).announceHashLockAggregateBonded(getListener(type), signedHashLockTransaction, signedAggregateTransaction), aggregateTransaction);
HashLockRepository hashLockRepository = getRepositoryFactory(type).createHashLockRepository();
HashLockInfo hashLockInfo = get(hashLockRepository.getHashLock(hashLockTransaction.getHash()));
Assertions.assertNotNull(hashLockInfo);
Assertions.assertEquals(multisigAccount.getAddress(), hashLockInfo.getOwnerAddress());
Assertions.assertEquals(hashAmount.getAmount(), hashLockInfo.getAmount());
Assertions.assertEquals(LockStatus.UNUSED, hashLockInfo.getStatus());
Assertions.assertEquals(hashLockTransaction.getHash(), hashLockInfo.getHash());
Page<HashLockInfo> page = get(hashLockRepository.search(new HashLockSearchCriteria().address(multisigAccount.getAddress())));
Assertions.assertTrue(page.getData().stream().anyMatch(m -> m.getHash().equals(hashLockTransaction.getHash())));
Assertions.assertEquals(20, page.getPageSize());
sleep(1000);
return get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class TestHelper method createTestAccount.
public Account createTestAccount(RepositoryType type) {
Account testAccount = Account.generateNewAccount(this.networkType);
sendMosaicFromNemesis(type, testAccount.getAddress(), false);
return testAccount;
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class TransactionServiceIntegrationTest method testTransferCatCurrencyFromNemesis.
@ParameterizedTest
@EnumSource(RepositoryType.class)
public void testTransferCatCurrencyFromNemesis(RepositoryType type) {
String mosaicAlias = getNetworkCurrency().getNamespaceId().get().getFullName().get();
Account testAccount = helper().getTestAccount(type).getLeft();
String recipientAlias = "testaccount" + RandomUtils.nextInt(0, 10000);
helper().setAddressAlias(type, testAccount.getAddress(), recipientAlias);
String hash = transferUsingAliases(config().getNemesisAccount(), type, mosaicAlias, recipientAlias, BigInteger.TEN).getTransactionInfo().get().getHash().get();
List<Transaction> transactions = get(getTransactionService(type).resolveAliases(Collections.singletonList(hash)));
Assertions.assertEquals(1, transactions.size());
TransferTransaction resolvedTransaction = (TransferTransaction) transactions.get(0);
System.out.println(toJson(resolvedTransaction));
Assertions.assertEquals(testAccount.getAddress(), resolvedTransaction.getRecipient());
System.out.println(resolvedTransaction.getMosaics().get(0).getId());
Assertions.assertTrue(resolvedTransaction.getMosaics().get(0).getId() instanceof MosaicId);
Assertions.assertTrue(resolvedTransaction.getRecipient() instanceof Address);
}
Aggregations