Search in sources :

Example 6 with AccountInfo

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

the class AccountRepositoryOkHttpImpl method search.

@Override
public Observable<Page<AccountInfo>> search(AccountSearchCriteria criteria) {
    Integer pageSize = criteria.getPageSize();
    Integer pageNumber = criteria.getPageNumber();
    String offset = criteria.getOffset();
    Order order = toDto(criteria.getOrder());
    AccountOrderByEnum orderBy = criteria.getOrderBy() == null ? null : AccountOrderByEnum.fromValue(criteria.getOrderBy().getValue());
    String mosaicId = criteria.getMosaicId() == null ? null : criteria.getMosaicId().getIdAsHex();
    Callable<AccountPage> callback = () -> getClient().searchAccounts(pageSize, pageNumber, offset, order, orderBy, mosaicId);
    return exceptionHandling(call(callback).map(page -> this.toPage(page.getPagination(), page.getData().stream().map(this::toAccountInfo).collect(Collectors.toList()))));
}
Also used : Order(io.nem.symbol.sdk.openapi.okhttp_gson.model.Order) AccountOrderByEnum(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountOrderByEnum) AccountInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountInfoDTO) MapperUtils.toMosaicId(io.nem.symbol.core.utils.MapperUtils.toMosaicId) AccountLinkPublicKeyDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountLinkPublicKeyDTO) AccountRepository(io.nem.symbol.sdk.api.AccountRepository) Callable(java.util.concurrent.Callable) AccountDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountDTO) AccountType(io.nem.symbol.sdk.model.account.AccountType) AccountPage(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountPage) MapperUtils.toAddress(io.nem.symbol.core.utils.MapperUtils.toAddress) ObjectUtils(org.apache.commons.lang3.ObjectUtils) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) ActivityBucket(io.nem.symbol.sdk.model.account.ActivityBucket) AccountRoutesApi(io.nem.symbol.sdk.openapi.okhttp_gson.api.AccountRoutesApi) Observable(io.reactivex.Observable) ResolvedMosaic(io.nem.symbol.sdk.model.mosaic.ResolvedMosaic) SupplementalPublicKeysDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.SupplementalPublicKeysDTO) ApiClient(io.nem.symbol.sdk.openapi.okhttp_gson.invoker.ApiClient) AccountIds(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountIds) AccountOrderByEnum(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountOrderByEnum) AccountSearchCriteria(io.nem.symbol.sdk.api.AccountSearchCriteria) Collectors(java.util.stream.Collectors) Order(io.nem.symbol.sdk.openapi.okhttp_gson.model.Order) List(java.util.List) SupplementalAccountKeys(io.nem.symbol.sdk.model.account.SupplementalAccountKeys) PublicKey(io.nem.symbol.core.crypto.PublicKey) AccountLinkVotingKey(io.nem.symbol.sdk.model.account.AccountLinkVotingKey) Address(io.nem.symbol.sdk.model.account.Address) Collections(java.util.Collections) Page(io.nem.symbol.sdk.api.Page) AccountPage(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountPage)

Example 7 with AccountInfo

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

the class AccountRepositoryOkHttpImplTest method shouldGetAccountsInfoFromAddresses.

@Test
public void shouldGetAccountsInfoFromAddresses() throws ExecutionException, InterruptedException, ApiException {
    Account account = Account.generateNewAccount(this.networkType);
    Account nodeAccount = Account.generateNewAccount(this.networkType);
    Address address = account.getAddress();
    AccountDTO accountDTO = new AccountDTO();
    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));
    accountDTO.setVersion(1);
    accountDTO.setSupplementalPublicKeys(new SupplementalPublicKeysDTO().node(new AccountLinkPublicKeyDTO().publicKey(nodeAccount.getPublicKey())));
    AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
    accountInfoDTO.setAccount(accountDTO);
    BigInteger startHeight = BigInteger.ONE;
    BigInteger totalFeesPaid = BigInteger.valueOf(2);
    long beneficiaryCount = 3;
    BigInteger rawScore = BigInteger.valueOf(4);
    accountDTO.addActivityBucketsItem(new ActivityBucketDTO().startHeight(startHeight).totalFeesPaid(totalFeesPaid).beneficiaryCount(beneficiaryCount).rawScore(rawScore));
    mockRemoteCall(Collections.singletonList(accountInfoDTO));
    List<AccountInfo> resolvedAccountInfos = repository.getAccountsInfo(Collections.singletonList(address)).toFuture().get();
    Assertions.assertEquals(1, resolvedAccountInfos.size());
    AccountInfo resolvedAccountInfo = resolvedAccountInfos.get(0);
    Assertions.assertEquals(address, resolvedAccountInfo.getAddress());
    Assertions.assertEquals(AccountType.MAIN, resolvedAccountInfo.getAccountType());
    Assertions.assertEquals(nodeAccount.getPublicKey(), resolvedAccountInfo.getSupplementalAccountKeys().getNode().get().toHex());
    Assertions.assertEquals(1, resolvedAccountInfo.getActivityBuckets().size());
    Assertions.assertEquals(startHeight, resolvedAccountInfo.getActivityBuckets().get(0).getStartHeight());
    Assertions.assertEquals(totalFeesPaid, resolvedAccountInfo.getActivityBuckets().get(0).getTotalFeesPaid());
    Assertions.assertEquals(beneficiaryCount, resolvedAccountInfo.getActivityBuckets().get(0).getBeneficiaryCount());
    Assertions.assertEquals(rawScore, resolvedAccountInfo.getActivityBuckets().get(0).getRawScore());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) AccountLinkPublicKeyDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountLinkPublicKeyDTO) AccountInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountInfoDTO) Address(io.nem.symbol.sdk.model.account.Address) BigInteger(java.math.BigInteger) SupplementalPublicKeysDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.SupplementalPublicKeysDTO) AccountDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountDTO) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) ActivityBucketDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.ActivityBucketDTO) Test(org.junit.jupiter.api.Test)

Example 8 with AccountInfo

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

the class AccountRepositoryOkHttpImplTest method search.

@Test
public void search() throws Exception {
    Account account = Account.generateNewAccount(this.networkType);
    Address address = account.getAddress();
    Account nodeAccount = Account.generateNewAccount(this.networkType);
    AccountDTO accountDTO = new AccountDTO();
    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));
    accountDTO.setVersion(1);
    accountDTO.setSupplementalPublicKeys(new SupplementalPublicKeysDTO().node(new AccountLinkPublicKeyDTO().publicKey(nodeAccount.getPublicKey())));
    AccountInfoDTO accountInfoDTO = new AccountInfoDTO();
    accountInfoDTO.setAccount(accountDTO);
    BigInteger startHeight = BigInteger.ONE;
    BigInteger totalFeesPaid = BigInteger.valueOf(2);
    long beneficiaryCount = 3;
    BigInteger rawScore = BigInteger.valueOf(4);
    accountDTO.addActivityBucketsItem(new ActivityBucketDTO().startHeight(startHeight).totalFeesPaid(totalFeesPaid).beneficiaryCount(beneficiaryCount).rawScore(rawScore));
    mockRemoteCall(toPage(accountInfoDTO));
    List<AccountInfo> resolvedAccountInfos = repository.search(new AccountSearchCriteria().orderBy(AccountOrderBy.BALANCE)).toFuture().get().getData();
    Assertions.assertEquals(1, resolvedAccountInfos.size());
    AccountInfo resolvedAccountInfo = resolvedAccountInfos.get(0);
    Assertions.assertEquals(address, resolvedAccountInfo.getAddress());
    Assertions.assertEquals(AccountType.MAIN, resolvedAccountInfo.getAccountType());
    Assertions.assertEquals(nodeAccount.getPublicKey(), resolvedAccountInfo.getSupplementalAccountKeys().getNode().get().toHex());
    Assertions.assertEquals(1, resolvedAccountInfo.getActivityBuckets().size());
    Assertions.assertEquals(startHeight, resolvedAccountInfo.getActivityBuckets().get(0).getStartHeight());
    Assertions.assertEquals(totalFeesPaid, resolvedAccountInfo.getActivityBuckets().get(0).getTotalFeesPaid());
    Assertions.assertEquals(beneficiaryCount, resolvedAccountInfo.getActivityBuckets().get(0).getBeneficiaryCount());
    Assertions.assertEquals(rawScore, resolvedAccountInfo.getActivityBuckets().get(0).getRawScore());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) AccountLinkPublicKeyDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountLinkPublicKeyDTO) AccountInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountInfoDTO) AccountSearchCriteria(io.nem.symbol.sdk.api.AccountSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) BigInteger(java.math.BigInteger) SupplementalPublicKeysDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.SupplementalPublicKeysDTO) AccountDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountDTO) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) ActivityBucketDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.ActivityBucketDTO) Test(org.junit.jupiter.api.Test)

Example 9 with AccountInfo

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

the class AccountRepositoryOkHttpImplTest method shouldGetAccountInfo.

@Test
public void shouldGetAccountInfo() throws Exception {
    Account account = Account.generateNewAccount(this.networkType);
    Address address = account.getAddress();
    AccountDTO accountDTO = new AccountDTO();
    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);
    accountDTO.setVersion(1);
    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.okhttp_gson.model.AccountInfoDTO) Address(io.nem.symbol.sdk.model.account.Address) ArrayList(java.util.ArrayList) AccountDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountDTO) Mosaic(io.nem.symbol.sdk.openapi.okhttp_gson.model.Mosaic) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) Test(org.junit.jupiter.api.Test)

Example 10 with AccountInfo

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

the class AccountRepositoryIntegrationTest method getAccountsInfoFromAddresses.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getAccountsInfoFromAddresses(RepositoryType type) {
    Account account = config().getDefaultAccount();
    Address address = account.getAddress();
    List<AccountInfo> accountInfos = get(this.getAccountRepository(type).getAccountsInfo(Collections.singletonList(address)));
    assertEquals(1, accountInfos.size());
    assertEquals(account.getAddress(), accountInfos.get(0).getAddress());
    assertEquals(AccountType.UNLINKED, accountInfos.get(0).getAccountType());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Address(io.nem.symbol.sdk.model.account.Address) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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