Search in sources :

Example 16 with PublicAccount

use of io.nem.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.

the class AggregateTransactionTest method createAAggregateTransactionViaStaticConstructor.

@Test
void createAAggregateTransactionViaStaticConstructor() {
    TransferTransaction transferTx = TransferTransaction.create(new Deadline(2, ChronoUnit.HOURS), new Address("SDGLFW-DSHILT-IUHGIB-H5UGX2-VYF5VN-JEKCCD-BR26", NetworkType.MIJIN_TEST), Collections.emptyList(), PlainMessage.Empty, NetworkType.MIJIN_TEST);
    AggregateTransaction aggregateTx = AggregateTransaction.createComplete(new Deadline(2, ChronoUnit.HOURS), Arrays.asList(transferTx.toAggregate(new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", NetworkType.MIJIN_TEST))), NetworkType.MIJIN_TEST);
    assertEquals(NetworkType.MIJIN_TEST, aggregateTx.getNetworkType());
    assertTrue(2 == aggregateTx.getVersion());
    assertTrue(LocalDateTime.now().isBefore(aggregateTx.getDeadline().getLocalDateTime()));
    assertEquals(BigInteger.valueOf(0), aggregateTx.getFee());
    assertEquals(1, aggregateTx.getInnerTransactions().size());
}
Also used : Address(io.nem.sdk.model.account.Address) PublicAccount(io.nem.sdk.model.account.PublicAccount) Test(org.junit.jupiter.api.Test)

Example 17 with PublicAccount

use of io.nem.sdk.model.account.PublicAccount 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 18 with PublicAccount

use of io.nem.sdk.model.account.PublicAccount 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

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