Search in sources :

Example 1 with NamespaceInfo

use of io.nem.sdk.model.namespace.NamespaceInfo in project nem2-sdk-java by nemtech.

the class NamespaceHttpTest method getNamespace.

@Test
void getNamespace() throws ExecutionException, InterruptedException {
    NamespaceInfo namespaceInfo = namespaceHttp.getNamespace(XEM.NAMESPACEID).toFuture().get();
    assertEquals(new BigInteger("1"), namespaceInfo.getStartHeight());
    assertEquals(new BigInteger("-1"), namespaceInfo.getEndHeight());
    assertEquals(XEM.NAMESPACEID, namespaceInfo.getLevels().get(0));
}
Also used : BigInteger(java.math.BigInteger) NamespaceInfo(io.nem.sdk.model.namespace.NamespaceInfo) Test(org.junit.jupiter.api.Test)

Example 2 with NamespaceInfo

use of io.nem.sdk.model.namespace.NamespaceInfo in project nem2-sdk-java by nemtech.

the class NamespaceHttpTest method getNamespacesFromAccounts.

@Test
void getNamespacesFromAccounts() throws ExecutionException, InterruptedException {
    List<NamespaceInfo> namespacesInfo = namespaceHttp.getNamespacesFromAccounts(Collections.singletonList(Address.createFromRawAddress("SARNASAS2BIAB6LMFA3FPMGBPGIJGK6IJETM3ZSP"))).toFuture().get();
    assertEquals(1, namespacesInfo.size());
    assertEquals(new BigInteger("1"), namespacesInfo.get(0).getStartHeight());
    assertEquals(new BigInteger("-1"), namespacesInfo.get(0).getEndHeight());
    assertEquals(XEM.NAMESPACEID, namespacesInfo.get(0).getLevels().get(0));
}
Also used : BigInteger(java.math.BigInteger) NamespaceInfo(io.nem.sdk.model.namespace.NamespaceInfo) Test(org.junit.jupiter.api.Test)

Example 3 with NamespaceInfo

use of io.nem.sdk.model.namespace.NamespaceInfo in project nem2-sdk-java by nemtech.

the class NamespaceHttpTest method getNamespacesFromAccount.

@Test
void getNamespacesFromAccount() throws ExecutionException, InterruptedException {
    List<NamespaceInfo> namespacesInfo = namespaceHttp.getNamespacesFromAccount(Address.createFromRawAddress("SARNASAS2BIAB6LMFA3FPMGBPGIJGK6IJETM3ZSP")).toFuture().get();
    assertEquals(1, namespacesInfo.size());
    assertEquals(new BigInteger("1"), namespacesInfo.get(0).getStartHeight());
    assertEquals(new BigInteger("-1"), namespacesInfo.get(0).getEndHeight());
    assertEquals(XEM.NAMESPACEID, namespacesInfo.get(0).getLevels().get(0));
}
Also used : BigInteger(java.math.BigInteger) NamespaceInfo(io.nem.sdk.model.namespace.NamespaceInfo) Test(org.junit.jupiter.api.Test)

Example 4 with NamespaceInfo

use of io.nem.sdk.model.namespace.NamespaceInfo in project nem2-sdk-java by nemtech.

the class NamespaceHttp method getNamespacesFromAccounts.

private Observable<List<NamespaceInfo>> getNamespacesFromAccounts(List<Address> addresses, Optional<QueryParams> queryParams) {
    JsonObject requestBody = new JsonObject();
    requestBody.put("addresses", addresses.stream().map((address -> address.plain())).collect(Collectors.toList()));
    Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable();
    return networkTypeResolve.flatMap(networkType -> this.client.postAbs(this.url + "/account/namespaces" + (queryParams.isPresent() ? queryParams.get().toUrl() : "")).as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<NamespaceInfoDTO>>readValue(json.toString(), new TypeReference<List<NamespaceInfoDTO>>() {
    })).flatMapIterable(item -> item).map(namespaceInfoDTO -> new NamespaceInfo(namespaceInfoDTO.getMeta().isActive(), namespaceInfoDTO.getMeta().getIndex(), namespaceInfoDTO.getMeta().getId(), NamespaceType.rawValueOf(namespaceInfoDTO.getNamespace().getType()), namespaceInfoDTO.getNamespace().getDepth(), extractLevels(namespaceInfoDTO), new NamespaceId(namespaceInfoDTO.getNamespace().getParentId().extractIntArray()), new PublicAccount(namespaceInfoDTO.getNamespace().getOwner(), networkType), namespaceInfoDTO.getNamespace().getStartHeight().extractIntArray(), namespaceInfoDTO.getNamespace().getEndHeight().extractIntArray())).toList().toObservable());
}
Also used : NamespaceInfo(io.nem.sdk.model.namespace.NamespaceInfo) NamespaceName(io.nem.sdk.model.namespace.NamespaceName) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) MalformedURLException(java.net.MalformedURLException) NamespaceType(io.nem.sdk.model.namespace.NamespaceType) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) 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) Address(io.nem.sdk.model.account.Address) 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) NetworkType(io.nem.sdk.model.blockchain.NetworkType) PublicAccount(io.nem.sdk.model.account.PublicAccount) JsonObject(io.vertx.core.json.JsonObject) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) ArrayList(java.util.ArrayList) List(java.util.List) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.sdk.model.namespace.NamespaceInfo)

Aggregations

NamespaceInfo (io.nem.sdk.model.namespace.NamespaceInfo)4 BigInteger (java.math.BigInteger)3 Test (org.junit.jupiter.api.Test)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Address (io.nem.sdk.model.account.Address)1 PublicAccount (io.nem.sdk.model.account.PublicAccount)1 NetworkType (io.nem.sdk.model.blockchain.NetworkType)1 NamespaceId (io.nem.sdk.model.namespace.NamespaceId)1 NamespaceName (io.nem.sdk.model.namespace.NamespaceName)1 NamespaceType (io.nem.sdk.model.namespace.NamespaceType)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 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1