Search in sources :

Example 76 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class NamespaceRepositoryVertxImpl method getMosaicsNames.

@Override
public Observable<List<MosaicNames>> getMosaicsNames(List<MosaicId> ids) {
    MosaicIds mosaicIds = new MosaicIds();
    mosaicIds.mosaicIds(ids.stream().map(MosaicId::getIdAsHex).collect(Collectors.toList()));
    Consumer<Handler<AsyncResult<MosaicsNamesDTO>>> callback = handler -> getClient().getMosaicsNames(mosaicIds, handler);
    return exceptionHandling(call(callback).map(MosaicsNamesDTO::getMosaicNames).flatMapIterable(item -> item).map(this::toMosaicNames).toList().toObservable());
}
Also used : AliasTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.AliasTypeEnum) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) NamespaceDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceDTO) Addresses(io.nem.symbol.sdk.openapi.vertx.model.Addresses) NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) NamespaceRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.NamespaceRoutesApi) ArrayList(java.util.ArrayList) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) MapperUtils.toNamespaceId(io.nem.symbol.core.utils.MapperUtils.toNamespaceId) NamespaceSearchCriteria(io.nem.symbol.sdk.api.NamespaceSearchCriteria) ObjectUtils(org.apache.commons.lang3.ObjectUtils) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) MosaicAlias(io.nem.symbol.sdk.model.namespace.MosaicAlias) Observable(io.reactivex.Observable) AsyncResult(io.vertx.core.AsyncResult) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicNamesDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicNamesDTO) MapperUtils(io.nem.symbol.core.utils.MapperUtils) Alias(io.nem.symbol.sdk.model.namespace.Alias) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) MosaicsNamesDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicsNamesDTO) NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) NamespacePage(io.nem.symbol.sdk.openapi.vertx.model.NamespacePage) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) NamespaceNameDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceNameDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) NamespaceRegistrationTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.NamespaceRegistrationTypeEnum) EmptyAlias(io.nem.symbol.sdk.model.namespace.EmptyAlias) Collectors(java.util.stream.Collectors) NamespaceRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.NamespaceRoutesApiImpl) MosaicIds(io.nem.symbol.sdk.openapi.vertx.model.MosaicIds) NamespaceIds(io.nem.symbol.sdk.openapi.vertx.model.NamespaceIds) AccountNames(io.nem.symbol.sdk.model.account.AccountNames) NamespaceRegistrationType(io.nem.symbol.sdk.model.namespace.NamespaceRegistrationType) Consumer(java.util.function.Consumer) NamespaceInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.NamespaceInfoDTO) List(java.util.List) AccountNamesDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountNamesDTO) AliasType(io.nem.symbol.sdk.model.namespace.AliasType) AccountsNamesDTO(io.nem.symbol.sdk.openapi.vertx.model.AccountsNamesDTO) Optional(java.util.Optional) Address(io.nem.symbol.sdk.model.account.Address) Handler(io.vertx.core.Handler) Page(io.nem.symbol.sdk.api.Page) AddressAlias(io.nem.symbol.sdk.model.namespace.AddressAlias) MosaicsNamesDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicsNamesDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Handler(io.vertx.core.Handler) MosaicIds(io.nem.symbol.sdk.openapi.vertx.model.MosaicIds)

Example 77 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class MosaicRepositoryOkHttpImplTest method shouldGetMosaicsFromAccount.

@Test
public void shouldGetMosaicsFromAccount() throws Exception {
    PublicAccount publicAccount = Account.generateNewAccount(networkType).getPublicAccount();
    MosaicId mosaicId = MapperUtils.toMosaicId("481110499AAA");
    Address ownerAddress = Account.generateNewAccount(networkType).getAddress();
    MosaicDTO mosaicDto = new MosaicDTO();
    mosaicDto.setOwnerAddress(ownerAddress.encoded());
    mosaicDto.setId("481110499AAA");
    mosaicDto.setRevision(123L);
    mosaicDto.setFlags(5);
    mosaicDto.setDivisibility(6);
    mosaicDto.setDuration(BigInteger.valueOf(7));
    mosaicDto.supply(BigInteger.valueOf(1000));
    mosaicDto.startHeight(BigInteger.valueOf(100));
    mosaicDto.setVersion(1);
    mockRemoteCall(toPage(new MosaicInfoDTO().mosaic(mosaicDto).id("ABC")));
    List<MosaicInfo> resolvedList = repository.search(new MosaicSearchCriteria().ownerAddress(publicAccount.getAddress())).toFuture().get().getData();
    Assertions.assertEquals(1, resolvedList.size());
    MosaicInfo mosaicInfo = resolvedList.get(0);
    Assertions.assertEquals(mosaicId, mosaicInfo.getMosaicId());
    Assertions.assertEquals(mosaicDto.getRevision(), mosaicInfo.getRevision());
    Assertions.assertEquals(mosaicDto.getOwnerAddress(), mosaicInfo.getOwnerAddress().encoded(networkType));
    Assertions.assertFalse(mosaicInfo.isTransferable());
    Assertions.assertEquals(6, mosaicInfo.getDivisibility());
    Assertions.assertEquals(BigInteger.valueOf(7), mosaicInfo.getDuration());
    Assertions.assertEquals(mosaicDto.getStartHeight(), mosaicInfo.getStartHeight());
    Assertions.assertEquals(mosaicDto.getSupply(), mosaicInfo.getSupply());
}
Also used : MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) Address(io.nem.symbol.sdk.model.account.Address) MosaicDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicDTO) MosaicInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicInfoDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) MosaicSearchCriteria(io.nem.symbol.sdk.api.MosaicSearchCriteria) Test(org.junit.jupiter.api.Test)

Example 78 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class NamespaceRepositoryOkHttpImplTest method shouldGetLinkedMosaicId.

@Test
public void shouldGetLinkedMosaicId() throws Exception {
    Address ownerAccount = Account.generateNewAccount(NetworkType.MIJIN_TEST).getAddress();
    NamespaceId namespaceId = NamespaceId.createFromName("accountalias");
    NamespaceInfoDTO dto = new NamespaceInfoDTO();
    NamespaceMetaDTO meta = new NamespaceMetaDTO();
    meta.setActive(true);
    dto.setId("SomeId");
    meta.setIndex(123);
    dto.setMeta(meta);
    NamespaceDTO namespace = new NamespaceDTO();
    namespace.setDepth(111);
    namespace.setRegistrationType(NamespaceRegistrationTypeEnum.NUMBER_0);
    namespace.setOwnerAddress(ownerAccount.encoded());
    AliasDTO alias = new AliasDTO();
    alias.setType(AliasTypeEnum.NUMBER_1);
    alias.setMosaicId("528280977531AAA");
    namespace.setAlias(alias);
    dto.setNamespace(namespace);
    mockRemoteCall(dto);
    MosaicId linkedMosaicId = repository.getLinkedMosaicId(namespaceId).toFuture().get();
    Assertions.assertNotNull(linkedMosaicId);
    Assertions.assertEquals(MapperUtils.fromHexToBigInteger("528280977531AAA"), linkedMosaicId.getId());
}
Also used : NamespaceDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceDTO) Address(io.nem.symbol.sdk.model.account.Address) NamespaceMetaDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceMetaDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) NamespaceInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceInfoDTO) AliasDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AliasDTO) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 79 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class CurrencyServiceImpl method getCurrency.

/**
 * Creates a network currency model given mosaic info and mosaic names
 */
private Currency getCurrency(MosaicInfo mosaicInfo, List<MosaicNames> mosaicNamesList) {
    MosaicId mosaicId = mosaicInfo.getMosaicId();
    Optional<String> namespaceName = getName(mosaicNamesList, mosaicId);
    Optional<NamespaceId> namespaceId = namespaceName.map(NamespaceId::createFromName);
    return createCurrency(mosaicInfo, namespaceId).build();
}
Also used : UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId)

Example 80 with MosaicId

use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class CurrencyServiceImpl method getNetworkCurrencies.

@Override
public Observable<NetworkCurrencies> getNetworkCurrencies() {
    return this.networkRepository.getNetworkProperties().flatMap(properties -> {
        if (properties.getChain() == null || properties.getChain().getCurrencyMosaicId() == null) {
            return Observable.error(new IllegalArgumentException("CurrencyMosaicId could not be loaded from network properties!!!"));
        }
        if (properties.getChain() == null || properties.getChain().getHarvestingMosaicId() == null) {
            return Observable.error(new IllegalArgumentException("HarvestingMosaicId could not be loaded from network properties!!"));
        }
        MosaicId currencyMosaicId = new MosaicId(FormatUtils.toSimpleHex(properties.getChain().getCurrencyMosaicId()));
        MosaicId harvestingMosaicId = new MosaicId(FormatUtils.toSimpleHex(properties.getChain().getHarvestingMosaicId()));
        List<MosaicId> mosaicIds = currencyMosaicId.equals(harvestingMosaicId) ? Collections.singletonList(currencyMosaicId) : Arrays.asList(currencyMosaicId, harvestingMosaicId);
        return this.getCurrencies(mosaicIds).map(currencies -> {
            Currency currency = currencies.stream().filter(c -> c.getMosaicId().filter(mosaicId -> mosaicId.equals(currencyMosaicId)).isPresent()).findFirst().orElseThrow(() -> new IllegalArgumentException("There is no Main Currency with id " + currencyMosaicId));
            Currency harvest = currencies.stream().filter(c -> c.getMosaicId().filter(mosaicId -> mosaicId.equals(harvestingMosaicId)).isPresent()).findFirst().orElseThrow(() -> new IllegalArgumentException("There is no Harvest Currency with id " + harvestingMosaicId));
            return new NetworkCurrencies(currency, harvest);
        });
    });
}
Also used : UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Currency(io.nem.symbol.sdk.model.mosaic.Currency) NetworkCurrencies(io.nem.symbol.sdk.model.mosaic.NetworkCurrencies)

Aggregations

MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)138 Test (org.junit.jupiter.api.Test)92 Address (io.nem.symbol.sdk.model.account.Address)53 BigInteger (java.math.BigInteger)53 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 EnumSource (org.junit.jupiter.params.provider.EnumSource)23 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)19 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)18 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)17 Account (io.nem.symbol.sdk.model.account.Account)16 MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)15 ArrayList (java.util.ArrayList)13 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)12 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)10 MosaicGlobalRestrictionTransaction (io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction)10 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)10 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)7 Currency (io.nem.symbol.sdk.model.mosaic.Currency)7 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)7 MosaicNonce (io.nem.symbol.sdk.model.mosaic.MosaicNonce)7