Search in sources :

Example 11 with MosaicInfo

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

the class MosaicRepositoryVertxImpl method getMosaics.

@Override
public Observable<List<MosaicInfo>> getMosaics(List<MosaicId> ids) {
    MosaicIds mosaicIds = new MosaicIds();
    mosaicIds.mosaicIds(ids.stream().map(MosaicId::getIdAsHex).collect(Collectors.toList()));
    Consumer<Handler<AsyncResult<List<MosaicInfoDTO>>>> callback = handler -> getClient().getMosaics(mosaicIds, handler);
    return exceptionHandling(call(callback).flatMapIterable(item -> item).map(this::createMosaicInfo).toList().toObservable());
}
Also used : MosaicRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.MosaicRoutesApi) MapperUtils(io.nem.symbol.core.utils.MapperUtils) MosaicRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.MosaicRoutesApiImpl) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) MapperUtils.toMosaicId(io.nem.symbol.core.utils.MapperUtils.toMosaicId) MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Collectors(java.util.stream.Collectors) MosaicIds(io.nem.symbol.sdk.openapi.vertx.model.MosaicIds) MosaicSearchCriteria(io.nem.symbol.sdk.api.MosaicSearchCriteria) MosaicPage(io.nem.symbol.sdk.openapi.vertx.model.MosaicPage) Consumer(java.util.function.Consumer) List(java.util.List) MosaicDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicDTO) ObjectUtils(org.apache.commons.lang3.ObjectUtils) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) MosaicInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicInfoDTO) Observable(io.reactivex.Observable) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) MosaicFlags(io.nem.symbol.sdk.model.mosaic.MosaicFlags) Page(io.nem.symbol.sdk.api.Page) MosaicRepository(io.nem.symbol.sdk.api.MosaicRepository) MapperUtils.toMosaicId(io.nem.symbol.core.utils.MapperUtils.toMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Handler(io.vertx.core.Handler) List(java.util.List) MosaicIds(io.nem.symbol.sdk.openapi.vertx.model.MosaicIds)

Example 12 with MosaicInfo

use of io.nem.symbol.sdk.model.mosaic.MosaicInfo 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 13 with MosaicInfo

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

the class MosaicDefinitionTransactionIntegrationTest method standaloneMosaicDefinitionTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void standaloneMosaicDefinitionTransaction(RepositoryType type) {
    MosaicId mosaicId = createMosaic(type);
    sleep(1000);
    MosaicInfo mosaicInfo = get(getRepositoryFactory(type).createMosaicRepository().getMosaic(mosaicId));
    Assertions.assertEquals(mosaicId, mosaicInfo.getMosaicId());
    Assertions.assertEquals(4, mosaicInfo.getDivisibility());
    Assertions.assertTrue(mosaicInfo.isTransferable());
    Assertions.assertTrue(mosaicInfo.isSupplyMutable());
    Assertions.assertTrue(mosaicInfo.isRestrictable());
    Assertions.assertEquals(100, mosaicInfo.getDuration().intValue());
}
Also used : MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with MosaicInfo

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

the class MosaicRepositoryVertxImplTest method shouldGetMosaic.

@Test
public void shouldGetMosaic() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MapperUtils.toMosaicId("481110499");
    MosaicDTO mosaicDto = new MosaicDTO();
    MosaicInfoDTO mosaicInfoDto = new MosaicInfoDTO();
    mosaicDto.setOwnerAddress(address.encoded());
    mosaicDto.setId("481110499");
    mosaicDto.setRevision(123L);
    mosaicDto.setVersion(1);
    mosaicDto.setFlags(5);
    mosaicDto.setDivisibility(6);
    mosaicDto.setDuration(BigInteger.valueOf(7));
    mosaicDto.supply(BigInteger.valueOf(1000));
    mosaicDto.startHeight(BigInteger.valueOf(100));
    mosaicInfoDto.setMosaic(mosaicDto);
    mockRemoteCall(mosaicInfoDto);
    MosaicInfo mosaicInfo = repository.getMosaic(mosaicId).toFuture().get();
    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.vertx.model.MosaicDTO) MosaicInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicInfoDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Example 15 with MosaicInfo

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

the class MosaicRepositoryVertxImplTest method shouldGetMosaics.

@Test
public void shouldGetMosaics() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MapperUtils.toMosaicId("481110499AAA");
    MosaicDTO mosaicDto = new MosaicDTO();
    MosaicInfoDTO mosaicInfoDto = new MosaicInfoDTO();
    mosaicDto.setOwnerAddress(address.encoded());
    mosaicDto.setId("481110499AAA");
    mosaicDto.setRevision(123L);
    mosaicDto.setFlags(5);
    mosaicDto.setVersion(1);
    mosaicDto.setDivisibility(6);
    mosaicDto.setDuration(BigInteger.valueOf(7));
    mosaicDto.supply(BigInteger.valueOf(1000));
    mosaicDto.startHeight(BigInteger.valueOf(100));
    mosaicInfoDto.setMosaic(mosaicDto);
    mockRemoteCall(Collections.singletonList(mosaicInfoDto));
    List<MosaicInfo> resolvedList = repository.getMosaics(Collections.singletonList(mosaicId)).toFuture().get();
    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.vertx.model.MosaicDTO) MosaicInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicInfoDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Aggregations

MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)19 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)15 Test (org.junit.jupiter.api.Test)13 Address (io.nem.symbol.sdk.model.account.Address)9 MosaicSearchCriteria (io.nem.symbol.sdk.api.MosaicSearchCriteria)6 Account (io.nem.symbol.sdk.model.account.Account)5 Currency (io.nem.symbol.sdk.model.mosaic.Currency)5 BigInteger (java.math.BigInteger)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)5 MosaicDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicDTO)4 MosaicInfoDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicInfoDTO)4 MosaicPaginationStreamer (io.nem.symbol.sdk.api.MosaicPaginationStreamer)3 MosaicRepository (io.nem.symbol.sdk.api.MosaicRepository)3 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)3 MosaicDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicDTO)3 MosaicInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicInfoDTO)3 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)2 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)2 NamespaceName (io.nem.symbol.sdk.model.namespace.NamespaceName)2