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());
}
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());
}
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());
}
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();
}
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);
});
});
}
Aggregations