Search in sources :

Example 1 with AccountRepository

use of io.nem.symbol.sdk.api.AccountRepository in project nem2-sdk-java by nemtech.

the class AccountRepositoryIntegrationTest method getAccountInfoNotExisting.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getAccountInfoNotExisting(RepositoryType type) {
    AccountRepository accountHttp = getRepositoryFactory(type).createAccountRepository();
    Address addressObject = Address.createFromPublicKey("67F69FA4BFCD158F6E1AF1ABC82F725F5C5C4710D6E29217B12BE66397435DFB", getNetworkType());
    RepositoryCallException exception = Assertions.assertThrows(RepositoryCallException.class, () -> get(accountHttp.getAccountInfo(addressObject)));
    Assertions.assertTrue(exception.getMessage().contains("ApiException: Not Found - 404 - ResourceNotFound - no resource exists with id"));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) RepositoryCallException(io.nem.symbol.sdk.api.RepositoryCallException) AccountRepository(io.nem.symbol.sdk.api.AccountRepository) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with AccountRepository

use of io.nem.symbol.sdk.api.AccountRepository in project nem2-sdk-java by nemtech.

the class MerkleLoaderIntegrationTest method accounts.

public List<Arguments> accounts() {
    RepositoryFactory repositoryFactory = getRepositoryFactory(DEFAULT_REPOSITORY_TYPE);
    AccountRepository repository = repositoryFactory.createAccountRepository();
    return getArguments(repository, new AccountSearchCriteria().order(ORDER_BY));
}
Also used : AccountSearchCriteria(io.nem.symbol.sdk.api.AccountSearchCriteria) AccountRepository(io.nem.symbol.sdk.api.AccountRepository) RestrictionAccountRepository(io.nem.symbol.sdk.api.RestrictionAccountRepository) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory)

Example 3 with AccountRepository

use of io.nem.symbol.sdk.api.AccountRepository 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 4 with AccountRepository

use of io.nem.symbol.sdk.api.AccountRepository 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)

Example 5 with AccountRepository

use of io.nem.symbol.sdk.api.AccountRepository in project nem2-sdk-java by nemtech.

the class StateProofServiceTest method account.

@Test
void account() throws Exception {
    AccountRepository repository = mock(AccountRepository.class);
    when(factory.createAccountRepository()).thenReturn(repository);
    Address id = Address.generateRandom(NetworkType.MIJIN_TEST);
    AccountInfo state = Mockito.mock(AccountInfo.class);
    when(state.getAddress()).thenReturn(id);
    when(state.serialize()).thenReturn(ConvertUtils.fromHexToBytes(serialized));
    when(repository.getAccountInfo(eq(id))).thenReturn(Observable.just(state));
    when(repository.getAccountInfoMerkle(eq(id))).thenReturn(Observable.just(tree));
    StateMerkleProof<AccountInfo> proof = service.account(id).toFuture().get();
    Assertions.assertTrue(proof.isValid());
    Assertions.assertEquals(state, proof.getState());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) AccountRepository(io.nem.symbol.sdk.api.AccountRepository) RestrictionAccountRepository(io.nem.symbol.sdk.api.RestrictionAccountRepository) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) Test(org.junit.jupiter.api.Test)

Aggregations

AccountRepository (io.nem.symbol.sdk.api.AccountRepository)5 RepositoryCallException (io.nem.symbol.sdk.api.RepositoryCallException)3 AccountInfo (io.nem.symbol.sdk.model.account.AccountInfo)3 Address (io.nem.symbol.sdk.model.account.Address)3 MultisigAccountInfo (io.nem.symbol.sdk.model.account.MultisigAccountInfo)3 MultisigRepository (io.nem.symbol.sdk.api.MultisigRepository)2 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)2 RestrictionAccountRepository (io.nem.symbol.sdk.api.RestrictionAccountRepository)2 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)2 AddressAliasTransaction (io.nem.symbol.sdk.model.transaction.AddressAliasTransaction)2 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)2 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)2 MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)2 MosaicDefinitionTransaction (io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction)2 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)2 MultisigAccountModificationTransaction (io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction)2 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)2 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)2 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)2 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)2