feat: implement `Client.ping()`
@@ -19,6 +19,7 @@ import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.TimeoutException;
/**
* Managed client for use on the Hedera Hashgraph network.
@@ -174,16 +175,14 @@ public final class Client implements AutoCloseable {
if (config.network == null) {
throw new Exception("Network is not set in provided json object");
- }
- else if (config.network.isJsonObject()) {
+ } else if (config.network.isJsonObject()) {
var networks = config.network.getAsJsonObject();
Map<String, AccountId> nodes = new HashMap<>(networks.size());
for (Map.Entry<String, JsonElement> entry : networks.entrySet()) {
nodes.put(entry.getValue().toString().replace("\"", ""), AccountId.fromString(entry.getKey().toString().replace("\"", "")));
}
client = new Client(nodes);
- }
- else{
+ } else {
String networks = config.network.getAsString();
switch (networks) {
case "mainnet":
@@ -216,8 +215,7 @@ public final class Client implements AutoCloseable {
listMirrors.add(mirrors.get(i).getAsString().replace("\"", ""));
}
client.setMirrorNetwork(listMirrors);
- }
- else{
+ } else {
String mirror = config.mirrorNetwork.getAsString();
switch (mirror) {
case "mainnet":
@@ -272,11 +270,17 @@ public final class Client implements AutoCloseable {
return this;
}
-
public Map<String, AccountId> getNetwork() {
return network.network;
}
+ public void ping(AccountId nodeAccountId) throws TimeoutException, HederaPreCheckStatusException {
+ new AccountBalanceQuery()
+ .setAccountId(nodeAccountId)
+ .setNodeAccountIds(List.of(nodeAccountId))
+ .execute(this);
+ }
+
/**
* Set the account that will, by default, be paying for transactions and queries built with
* this client.
