Search in sources :

Example 11 with AccountInfo

use of io.nem.symbol.sdk.model.account.AccountInfo in project nem2-sdk-java by nemtech.

the class AccountRepositoryIntegrationTest method getAccountInfo.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getAccountInfo(RepositoryType type) {
    Account testAccount = this.config().getDefaultAccount();
    Observable<AccountInfo> accountInfo1 = this.getAccountRepository(type).getAccountInfo(testAccount.getPublicAccount().getAddress());
    AccountInfo accountInfo = get(accountInfo1);
    assertEquals(testAccount.getPublicKey(), accountInfo.getPublicKey().toHex());
    assertEquals(AccountType.UNLINKED, accountInfo.getAccountType());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with AccountInfo

use of io.nem.symbol.sdk.model.account.AccountInfo in project nem2-sdk-java by nemtech.

the class AccountRepositoryVertxImplTest method shouldGetAccountInfo.

@Test
public void shouldGetAccountInfo() throws Exception {
    Account account = Account.generateNewAccount(this.networkType);
    Address address = account.getAddress();
    AccountDTO accountDTO = new AccountDTO();
    accountDTO.setVersion(1);
    accountDTO.setAccountType(AccountTypeEnum.NUMBER_1);
    accountDTO.setAddress(encodeAddress(address));
    accountDTO.setAddressHeight(BigInteger.TEN);
    accountDTO.setPublicKeyHeight(BigInteger.valueOf(20));
    accountDTO.setPublicKey(account.getPublicAccount().getPublicKey().toHex());
    accountDTO.setImportance(BigInteger.valueOf(5));
    accountDTO.setImportanceHeight(BigInteger.valueOf(10));
    List<Mosaic> mosaicDtos = new ArrayList<>();
    mosaicDtos.add(new Mosaic().id("0000000000000ABC").amount(BigInteger.TEN));
    accountDTO.setMosaics(mosaicDtos);
    AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
    accountInfoDTO.setAccount(accountDTO);
    mockRemoteCall(accountInfoDTO);
    AccountInfo resolvedAccountInfo = repository.getAccountInfo(address).toFuture().get();
    Assertions.assertEquals(address, resolvedAccountInfo.getAddress());
    Assertions.assertEquals(AccountType.MAIN, resolvedAccountInfo.getAccountType());
    Assertions.assertEquals(1, resolvedAccountInfo.getMosaics().size());
    Assertions.assertEquals("0000000000000ABC", resolvedAccountInfo.getMosaics().get(0).getId().getIdAsHex());
    Assertions.assertEquals(BigInteger.TEN, resolvedAccountInfo.getMosaics().get(0).getAmount());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) AccountInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO) Address(io.nem.symbol.sdk.model.account.Address) ArrayList(java.util.ArrayList) AccountDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountDTO) Mosaic(io.nem.symbol.sdk.openapi.vertx.model.Mosaic) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) Test(org.junit.jupiter.api.Test)

Example 13 with AccountInfo

use of io.nem.symbol.sdk.model.account.AccountInfo 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()));
}
Also used : MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) Arrays(java.util.Arrays) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) HashLockRepository(io.nem.symbol.sdk.api.HashLockRepository) Account(io.nem.symbol.sdk.model.account.Account) AccountRepository(io.nem.symbol.sdk.api.AccountRepository) Future(java.util.concurrent.Future) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) Pair(org.apache.commons.lang3.tuple.Pair) Duration(java.time.Duration) Map(java.util.Map) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) BigInteger(java.math.BigInteger) Listener(io.nem.symbol.sdk.api.Listener) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) MosaicDefinitionTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransactionFactory) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) BlockDuration(io.nem.symbol.sdk.model.blockchain.BlockDuration) AddressAliasTransactionFactory(io.nem.symbol.sdk.model.transaction.AddressAliasTransactionFactory) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) Set(java.util.Set) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) LockStatus(io.nem.symbol.sdk.model.transaction.LockStatus) MultisigAccountModificationTransactionFactory(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransactionFactory) HashLockSearchCriteria(io.nem.symbol.sdk.api.HashLockSearchCriteria) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Currency(io.nem.symbol.sdk.model.mosaic.Currency) List(java.util.List) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) JsonHelper(io.nem.symbol.sdk.model.transaction.JsonHelper) ExceptionUtils(io.nem.symbol.core.utils.ExceptionUtils) AggregateTransactionFactory(io.nem.symbol.sdk.model.transaction.AggregateTransactionFactory) Address(io.nem.symbol.sdk.model.account.Address) Page(io.nem.symbol.sdk.api.Page) MosaicSupplyChangeTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransactionFactory) HashLockTransactionFactory(io.nem.symbol.sdk.model.transaction.HashLockTransactionFactory) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) HashMap(java.util.HashMap) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) Stored(io.nem.symbol.sdk.model.Stored) LinkedHashMap(java.util.LinkedHashMap) MosaicAliasTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicAliasTransactionFactory) MultisigRepository(io.nem.symbol.sdk.api.MultisigRepository) TransactionService(io.nem.symbol.sdk.api.TransactionService) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) MosaicSupplyChangeActionType(io.nem.symbol.sdk.model.mosaic.MosaicSupplyChangeActionType) Observable(io.reactivex.Observable) JsonHelperJackson2(io.nem.symbol.sdk.infrastructure.vertx.JsonHelperJackson2) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) File(java.io.File) AccountNames(io.nem.symbol.sdk.model.account.AccountNames) TimeUnit(java.util.concurrent.TimeUnit) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) RepositoryFactoryOkHttpImpl(io.nem.symbol.sdk.infrastructure.okhttp.RepositoryFactoryOkHttpImpl) NamespaceRegistrationTransactionFactory(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransactionFactory) Assertions(org.junit.jupiter.api.Assertions) HashLockInfo(io.nem.symbol.sdk.model.transaction.HashLockInfo) RepositoryFactoryVertxImpl(io.nem.symbol.sdk.infrastructure.vertx.RepositoryFactoryVertxImpl) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) MosaicFlags(io.nem.symbol.sdk.model.mosaic.MosaicFlags) AliasAction(io.nem.symbol.sdk.model.namespace.AliasAction) MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) Collections(java.util.Collections) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) MultisigRepository(io.nem.symbol.sdk.api.MultisigRepository) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) AccountRepository(io.nem.symbol.sdk.api.AccountRepository) HashLockInfo(io.nem.symbol.sdk.model.transaction.HashLockInfo) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) HashLockSearchCriteria(io.nem.symbol.sdk.api.HashLockSearchCriteria) HashLockRepository(io.nem.symbol.sdk.api.HashLockRepository) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction)

Example 14 with AccountInfo

use of io.nem.symbol.sdk.model.account.AccountInfo in project nem2-sdk-java by nemtech.

the class MosaicAliasTransactionIntegrationTest method sendMosaicAliasTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void sendMosaicAliasTransaction(RepositoryType type) {
    String namespaceName = "test-root-namespace-for-mosaic-alias-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
    Account account = this.config().getDefaultAccount();
    AccountInfo accountInfo = get(getRepositoryFactory(type).createAccountRepository().getAccountInfo(account.getPublicAccount().getAddress()));
    Assertions.assertFalse(accountInfo.getMosaics().isEmpty());
    MosaicId mosaicId = createMosaic(account, type, BigInteger.ZERO, null);
    NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, helper().getDuration()).maxFee(maxFee).build();
    NamespaceId rootNamespaceId = announceAggregateAndValidate(type, namespaceRegistrationTransaction, account).getLeft().getNamespaceId();
    MosaicAliasTransaction addressAliasTransaction = MosaicAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, mosaicId).maxFee(maxFee).build();
    announceAggregateAndValidate(type, addressAliasTransaction, account);
    List<MosaicNames> accountNames = get(getRepositoryFactory(type).createNamespaceRepository().getMosaicsNames(Collections.singletonList(mosaicId)));
    Assertions.assertEquals(1, accountNames.size());
    assertEquals(1, accountNames.size());
    assertEquals(mosaicId, accountNames.get(0).getMosaicId());
    assertTrue(accountNames.get(0).getNames().stream().anyMatch(n -> namespaceName.equals(n.getName())));
}
Also used : NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) Account(io.nem.symbol.sdk.model.account.Account) EnumSource(org.junit.jupiter.params.provider.EnumSource) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicAliasTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicAliasTransactionFactory) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TestInstance(org.junit.jupiter.api.TestInstance) NamespaceRegistrationTransactionFactory(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransactionFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) Assertions(org.junit.jupiter.api.Assertions) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AliasAction(io.nem.symbol.sdk.model.namespace.AliasAction) Collections(java.util.Collections) Account(io.nem.symbol.sdk.model.account.Account) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with AccountInfo

use of io.nem.symbol.sdk.model.account.AccountInfo in project nem2-sdk-java by nemtech.

the class TestHelper method createMultisigAccountComplete.

public MultisigAccountInfo createMultisigAccountComplete(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));
    try {
        MultisigAccountInfo multisigAccountInfo = get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
        System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " already exist");
        System.out.println(getJsonHelper().print(multisigAccountInfo));
        return multisigAccountInfo;
    } catch (RepositoryCallException e) {
        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.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(convertIntoMultisigTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
    SignedTransaction signedAggregateTransaction = aggregateTransaction.signTransactionWithCosigners(multisigAccount, Arrays.asList(accounts), getGenerationHash());
    Transaction aggregateTransaciton = get(getTransactionService(type).announce(getListener(type), signedAggregateTransaction));
    sleep(1000);
    Assertions.assertEquals(aggregateTransaciton.getTransactionInfo().get().getHash().get(), signedAggregateTransaction.getHash());
    return get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
}
Also used : MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) MultisigRepository(io.nem.symbol.sdk.api.MultisigRepository) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) AccountRepository(io.nem.symbol.sdk.api.AccountRepository) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction)

Aggregations

AccountInfo (io.nem.symbol.sdk.model.account.AccountInfo)16 Address (io.nem.symbol.sdk.model.account.Address)12 Account (io.nem.symbol.sdk.model.account.Account)10 Test (org.junit.jupiter.api.Test)7 AccountRepository (io.nem.symbol.sdk.api.AccountRepository)6 AccountSearchCriteria (io.nem.symbol.sdk.api.AccountSearchCriteria)6 BigInteger (java.math.BigInteger)6 Collections (java.util.Collections)5 List (java.util.List)5 Page (io.nem.symbol.sdk.api.Page)4 AccountDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountDTO)4 AccountInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountInfoDTO)4 AccountDTO (io.nem.symbol.sdk.openapi.vertx.model.AccountDTO)4 AccountInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.AccountInfoDTO)4 AccountLinkPublicKeyDTO (io.nem.symbol.sdk.openapi.vertx.model.AccountLinkPublicKeyDTO)4 SupplementalPublicKeysDTO (io.nem.symbol.sdk.openapi.vertx.model.SupplementalPublicKeysDTO)4 Observable (io.reactivex.Observable)4 MultisigAccountInfo (io.nem.symbol.sdk.model.account.MultisigAccountInfo)3 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)3 MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)3