Search in sources :

Example 11 with NamespaceId

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

the class RegisterNamespaceTransactionTest method serializationSubNamespace.

@Test
@DisplayName("Serialization sub namespace")
void serializationSubNamespace() {
    // Generated at nem2-library-js/test/transactions/RegisterNamespaceTransaction.spec.js
    byte[] expected = new byte[] { (byte) 150, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, (byte) 144, 78, 65, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 126, (byte) 233, (byte) 179, (byte) 184, (byte) 175, (byte) 223, 83, 64, 3, 18, (byte) 152, 27, 120, 121, (byte) 163, 113, 12, 115, 117, 98, 110, 97, 109, 101, 115, 112, 97, 99, 101 };
    RegisterNamespaceTransaction registerNamespaceTransaction = RegisterNamespaceTransaction.createSubNamespace(new FakeDeadline(), "subnamespace", new NamespaceId(new BigInteger("4635294387305441662")), NetworkType.MIJIN_TEST);
    byte[] actual = registerNamespaceTransaction.generateBytes();
    assertArrayEquals(expected, actual);
}
Also used : BigInteger(java.math.BigInteger) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with NamespaceId

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

the class RegisterNamespaceTransactionTest method createANamespaceCreationSubNamespaceTransactionViaStaticConstructor.

@Test
void createANamespaceCreationSubNamespaceTransactionViaStaticConstructor() {
    RegisterNamespaceTransaction registerNamespaceTransaction = RegisterNamespaceTransaction.createSubNamespace(new Deadline(2, ChronoUnit.HOURS), "newnamespace", new NamespaceId(new BigInteger("4635294387305441662")), NetworkType.MIJIN_TEST);
    assertEquals(NetworkType.MIJIN_TEST, registerNamespaceTransaction.getNetworkType());
    assertTrue(2 == registerNamespaceTransaction.getVersion());
    assertTrue(LocalDateTime.now().isBefore(registerNamespaceTransaction.getDeadline().getLocalDateTime()));
    assertEquals(BigInteger.valueOf(0), registerNamespaceTransaction.getFee());
    assertEquals("newnamespace", registerNamespaceTransaction.getNamespaceName());
    assertEquals(NamespaceType.SubNamespace, registerNamespaceTransaction.getNamespaceType());
    assertEquals(new BigInteger("-7487193294859220686"), registerNamespaceTransaction.getNamespaceId().getId());
    assertEquals(new BigInteger("4635294387305441662"), registerNamespaceTransaction.getParentId().get().getId());
}
Also used : BigInteger(java.math.BigInteger) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 13 with NamespaceId

use of io.nem.sdk.model.namespace.NamespaceId 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)

Example 14 with NamespaceId

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

the class MosaicHttp method getMosaicNames.

@Override
public Observable<List<MosaicName>> getMosaicNames(List<MosaicId> mosaicIds) {
    JsonObject requestBody = new JsonObject();
    requestBody.put("mosaicIds", mosaicIds.stream().map(id -> UInt64.bigIntegerToHex(id.getId())).collect(Collectors.toList()));
    return this.client.postAbs(this.url + "/mosaic/names").as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<MosaicNameDTO>>readValue(json.toString(), new TypeReference<List<MosaicNameDTO>>() {
    })).flatMapIterable(item -> item).map(mosaicNameDTO -> new MosaicName(new MosaicId(mosaicNameDTO.getMosaicId().extractIntArray()), mosaicNameDTO.getName(), new NamespaceId(mosaicNameDTO.getParentId().extractIntArray()))).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) MosaicId(io.nem.sdk.model.mosaic.MosaicId) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) MosaicName(io.nem.sdk.model.mosaic.MosaicName)

Example 15 with NamespaceId

use of io.nem.sdk.model.namespace.NamespaceId 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

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