use of io.nem.sdk.model.blockchain.NetworkType in project nem2-sdk-java by nemtech.
the class AccountHttp method getAccountsInfo.
@Override
public Observable<List<AccountInfo>> getAccountsInfo(List<Address> addresses) {
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.toString()).as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<AccountInfoDTO>>readValue(json.toString(), new TypeReference<List<AccountInfoDTO>>() {
})).flatMapIterable(item -> item).map(AccountInfoDTO::getAccount).map(accountDTO -> new AccountInfo(Address.createFromRawAddress(accountDTO.getAddressEncoded()), accountDTO.getAddressHeight().extractIntArray(), accountDTO.getPublicKey(), accountDTO.getPublicKeyHeight().extractIntArray(), accountDTO.getImportance().extractIntArray(), accountDTO.getImportanceHeight().extractIntArray(), accountDTO.getMosaics().stream().map(mosaicDTO -> new Mosaic(new MosaicId(mosaicDTO.getId().extractIntArray()), mosaicDTO.getAmount().extractIntArray())).collect(Collectors.toList()))).toList().toObservable());
}
use of io.nem.sdk.model.blockchain.NetworkType in project nem2-sdk-java by nemtech.
the class Listener method open.
/**
* @return a {@link CompletableFuture} that resolves when the websocket connection is opened
*/
public CompletableFuture<Void> open() {
HttpClient httpClient = Vertx.vertx().createHttpClient();
CompletableFuture<Void> future = new CompletableFuture<>();
if (this.webSocket != null) {
return CompletableFuture.completedFuture(null);
}
RequestOptions requestOptions = new RequestOptions();
requestOptions.setHost(this.url.getHost());
requestOptions.setPort(this.url.getPort());
requestOptions.setURI("/ws");
httpClient.websocket(requestOptions, webSocket -> {
this.webSocket = webSocket;
webSocket.handler(handler -> {
JsonObject message = handler.toJsonObject();
if (message.containsKey("uid")) {
this.UID = message.getString("uid");
future.complete(null);
} else if (message.containsKey("transaction")) {
this.messageSubject.onNext(new ListenerMessage(ListenerChannel.rawValueOf(message.getJsonObject("meta").getString("channelName")), new TransactionMapping().apply(message)));
} else if (message.containsKey("block")) {
final JsonObject meta = message.getJsonObject("meta");
final JsonObject block = message.getJsonObject("block");
int rawNetworkType = (int) Long.parseLong(Integer.toHexString(block.getInteger("version")).substring(0, 2), 16);
final NetworkType networkType;
if (rawNetworkType == NetworkType.MIJIN_TEST.getValue())
networkType = NetworkType.MIJIN_TEST;
else if (rawNetworkType == NetworkType.MIJIN.getValue())
networkType = NetworkType.MIJIN;
else if (rawNetworkType == NetworkType.MAIN_NET.getValue())
networkType = NetworkType.MAIN_NET;
else
networkType = NetworkType.TEST_NET;
final int version = (int) Long.parseLong(Integer.toHexString(block.getInteger("version")).substring(2, 4), 16);
this.messageSubject.onNext(new ListenerMessage(ListenerChannel.BLOCK, new BlockInfo(meta.getString("hash"), meta.getString("generationHash"), Optional.empty(), Optional.empty(), block.getString("signature"), new PublicAccount(block.getString("signer"), networkType), networkType, version, block.getInteger("type"), extractBigInteger(block.getJsonArray("height")), extractBigInteger(block.getJsonArray("timestamp")), extractBigInteger(block.getJsonArray("difficulty")), block.getString("previousBlockHash"), block.getString("blockTransactionsHash"))));
} else if (message.containsKey("status")) {
this.messageSubject.onNext(new ListenerMessage(ListenerChannel.STATUS, new TransactionStatusError(message.getString("hash"), message.getString("status"), new Deadline(extractBigInteger(message.getJsonArray("deadline"))))));
} else if (message.containsKey("meta")) {
this.messageSubject.onNext(new ListenerMessage(ListenerChannel.rawValueOf(message.getJsonObject("meta").getString("channelName")), message.getJsonObject("meta").getString("hash")));
} else if (message.containsKey("parentHash")) {
this.messageSubject.onNext(new ListenerMessage(ListenerChannel.COSIGNATURE, new CosignatureSignedTransaction(message.getString("parenthash"), message.getString("signature"), message.getString("signer"))));
}
});
});
return future;
}
use of io.nem.sdk.model.blockchain.NetworkType in project nem2-sdk-java by nemtech.
the class NetworkHttpTest method getNetworkType.
@Test
void getNetworkType() throws ExecutionException, InterruptedException {
NetworkType networkType = networkHttp.getNetworkType().toFuture().get();
assertEquals(NetworkType.MIJIN_TEST.getValue(), networkType.getValue());
}
use of io.nem.sdk.model.blockchain.NetworkType 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.blockchain.NetworkType 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