Search in sources :

Example 1 with MosaicInfo

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

the class MosaicHttpTest method getMosaic.

@Test
void getMosaic() throws ExecutionException, InterruptedException {
    MosaicInfo mosaicInfo = mosaicHttp.getMosaic(XEM.MOSAICID).toFuture().get();
    assertEquals(new BigInteger("1"), mosaicInfo.getHeight());
    assertEquals(XEM.NAMESPACEID, mosaicInfo.getNamespaceId());
    assertEquals(XEM.MOSAICID, mosaicInfo.getMosaicId());
}
Also used : MosaicInfo(io.nem.sdk.model.mosaic.MosaicInfo) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 2 with MosaicInfo

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

the class MosaicHttp method getMosaics.

@Override
public Observable<List<MosaicInfo>> getMosaics(List<MosaicId> mosaicIds) {
    JsonObject requestBody = new JsonObject();
    requestBody.put("mosaicIds", mosaicIds.stream().map(id -> UInt64.bigIntegerToHex(id.getId())).collect(Collectors.toList()));
    Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable();
    return networkTypeResolve.flatMap(networkType -> this.client.postAbs(this.url + "/mosaic").as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<MosaicInfoDTO>>readValue(json.toString(), new TypeReference<List<MosaicInfoDTO>>() {
    })).flatMapIterable(item -> item).map(mosaicInfoDTO -> new MosaicInfo(mosaicInfoDTO.getMeta().isActive(), mosaicInfoDTO.getMeta().getIndex(), mosaicInfoDTO.getMeta().getId(), new NamespaceId(mosaicInfoDTO.getMosaic().getNamespaceId().extractIntArray()), new MosaicId(mosaicInfoDTO.getMosaic().getMosaicId().extractIntArray()), mosaicInfoDTO.getMosaic().getSupply().extractIntArray(), mosaicInfoDTO.getMosaic().getHeight().extractIntArray(), new PublicAccount(mosaicInfoDTO.getMosaic().getOwner(), networkType), extractMosaicProperties(mosaicInfoDTO.getMosaic().getProperties()))).toList().toObservable());
}
Also used : HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) MalformedURLException(java.net.MalformedURLException) MosaicName(io.nem.sdk.model.mosaic.MosaicName) MosaicInfo(io.nem.sdk.model.mosaic.MosaicInfo) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) UInt64(io.nem.sdk.model.transaction.UInt64) List(java.util.List) PublicAccount(io.nem.sdk.model.account.PublicAccount) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) MosaicProperties(io.nem.sdk.model.mosaic.MosaicProperties) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Optional(java.util.Optional) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) MosaicId(io.nem.sdk.model.mosaic.MosaicId) MosaicInfo(io.nem.sdk.model.mosaic.MosaicInfo) NetworkType(io.nem.sdk.model.blockchain.NetworkType) MosaicId(io.nem.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.sdk.model.account.PublicAccount) JsonObject(io.vertx.core.json.JsonObject) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) List(java.util.List) NamespaceId(io.nem.sdk.model.namespace.NamespaceId)

Aggregations

MosaicInfo (io.nem.sdk.model.mosaic.MosaicInfo)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 PublicAccount (io.nem.sdk.model.account.PublicAccount)1 NetworkType (io.nem.sdk.model.blockchain.NetworkType)1 MosaicId (io.nem.sdk.model.mosaic.MosaicId)1 MosaicName (io.nem.sdk.model.mosaic.MosaicName)1 MosaicProperties (io.nem.sdk.model.mosaic.MosaicProperties)1 NamespaceId (io.nem.sdk.model.namespace.NamespaceId)1 UInt64 (io.nem.sdk.model.transaction.UInt64)1 Observable (io.reactivex.Observable)1 JsonObject (io.vertx.core.json.JsonObject)1 HttpResponse (io.vertx.reactivex.ext.web.client.HttpResponse)1 BodyCodec (io.vertx.reactivex.ext.web.codec.BodyCodec)1 BigInteger (java.math.BigInteger)1 MalformedURLException (java.net.MalformedURLException)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.jupiter.api.Test)1