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