From f47f6405d19d95b34451a21b986cff6cce5ba39f Mon Sep 17 00:00:00 2001 From: successli Date: Thu, 31 May 2018 10:37:05 +0800 Subject: [PATCH] add CoreConfig class --- doc/index.md | 4 +- src/main/java/io/bytom/api/CoreConfig.java | 80 ++++++++++++++++++++++ src/main/java/io/bytom/api/NetInfo.java | 76 -------------------- .../{NetInfoTest.java => CoreConfigTest.java} | 9 ++- src/test/java/io/bytom/integration/UTXOTest.java | 1 - 5 files changed, 86 insertions(+), 84 deletions(-) create mode 100644 src/main/java/io/bytom/api/CoreConfig.java delete mode 100644 src/main/java/io/bytom/api/NetInfo.java rename src/test/java/io/bytom/integration/{NetInfoTest.java => CoreConfigTest.java} (76%) diff --git a/doc/index.md b/doc/index.md index 1bcf835..1839c8f 100644 --- a/doc/index.md +++ b/doc/index.md @@ -801,7 +801,7 @@ BlockHashRate getHashRate(Client client); ## Other API -#### 1.netInfo +#### 1.coreConfig ```java NetInfo getNetInfo(Client client); @@ -813,7 +813,7 @@ NetInfo getNetInfo(Client client); ##### Returns -- `NetInfo` - *netInfo*, a NetInfo object. +- `NetInfo` - *coreConfig*, a NetInfo object. ---- diff --git a/src/main/java/io/bytom/api/CoreConfig.java b/src/main/java/io/bytom/api/CoreConfig.java new file mode 100644 index 0000000..2166cca --- /dev/null +++ b/src/main/java/io/bytom/api/CoreConfig.java @@ -0,0 +1,80 @@ +package io.bytom.api; + +import com.google.gson.annotations.SerializedName; +import io.bytom.common.Utils; +import io.bytom.exception.BytomException; +import io.bytom.http.Client; +import org.apache.log4j.Logger; + +public class CoreConfig { + + + private static Logger logger = Logger.getLogger(CoreConfig.class); + + /** + * Call net-info api + * + * @param client + * @return + * @throws BytomException + */ + public static NetInfo getNetInfo(Client client) throws BytomException { + NetInfo netInfo = client.request("net-info", null, NetInfo.class); + + logger.info("net-info:"); + logger.info(netInfo.toJson()); + + return netInfo; + } + + public static class NetInfo { + /** + * listening, whether the node is listening. + */ + public boolean listening; + + /** + * syncing, whether the node is syncing. + */ + public boolean syncing; + + /** + * mining, whether the node is mining. + */ + public boolean mining; + + /** + * peer_count, current count of connected peers. + */ + @SerializedName("peer_count") + public int peerCount; + + /** + * current_block, current block height in the node's blockchain. + */ + @SerializedName("current_block") + public long currentBlock; + + /** + * highest_block, current highest block of the connected peers. + */ + @SerializedName("highest_block") + public long highestBlock; + + /** + * network_id, network id. + */ + @SerializedName("network_id") + public String networkID; + + /** + * version, bytom version. + */ + @SerializedName("version") + public String version; + + public String toJson() { + return Utils.serializer.toJson(this); + } + } +} diff --git a/src/main/java/io/bytom/api/NetInfo.java b/src/main/java/io/bytom/api/NetInfo.java deleted file mode 100644 index 1331e0a..0000000 --- a/src/main/java/io/bytom/api/NetInfo.java +++ /dev/null @@ -1,76 +0,0 @@ -package io.bytom.api; - -import com.google.gson.annotations.SerializedName; -import io.bytom.common.Utils; -import io.bytom.exception.BytomException; -import io.bytom.http.Client; -import org.apache.log4j.Logger; - -public class NetInfo { - - /** - * listening, whether the node is listening. - */ - public boolean listening; - - /** - * syncing, whether the node is syncing. - */ - public boolean syncing; - - /** - * mining, whether the node is mining. - */ - public boolean mining; - - /** - * peer_count, current count of connected peers. - */ - @SerializedName("peer_count") - public int peerCount; - - /** - * current_block, current block height in the node's blockchain. - */ - @SerializedName("current_block") - public long currentBlock; - - /** - * highest_block, current highest block of the connected peers. - */ - @SerializedName("highest_block") - public long highestBlock; - - /** - * network_id, network id. - */ - @SerializedName("network_id") - public String networkID; - - /** - * version, bytom version. - */ - @SerializedName("version") - public String version; - - private static Logger logger = Logger.getLogger(NetInfo.class); - - public String toJson() { - return Utils.serializer.toJson(this); - } - - /** - * Call net-info api - * - * @param client - * @return - * @throws BytomException - */ - public static NetInfo getNetInfo(Client client) throws BytomException { - NetInfo netInfo = client.request("net-info", null, NetInfo.class); - - logger.info("net-info:"); - logger.info(netInfo.toJson()); - return netInfo; - } -} diff --git a/src/test/java/io/bytom/integration/NetInfoTest.java b/src/test/java/io/bytom/integration/CoreConfigTest.java similarity index 76% rename from src/test/java/io/bytom/integration/NetInfoTest.java rename to src/test/java/io/bytom/integration/CoreConfigTest.java index cb095cc..f55f4b2 100644 --- a/src/test/java/io/bytom/integration/NetInfoTest.java +++ b/src/test/java/io/bytom/integration/CoreConfigTest.java @@ -1,13 +1,13 @@ package io.bytom.integration; import io.bytom.TestUtils; -import io.bytom.api.NetInfo; +import io.bytom.api.CoreConfig; import io.bytom.exception.BytomException; import io.bytom.http.Client; import org.junit.Assert; import org.junit.Test; -public class NetInfoTest { +public class CoreConfigTest { static Client client; @@ -19,12 +19,11 @@ public class NetInfoTest { } } - static NetInfo netInfo; - + static CoreConfig.NetInfo netInfo; @Test public void testNetInfo() throws Exception { - netInfo = NetInfo.getNetInfo(client); + netInfo = CoreConfig.getNetInfo(client); Assert.assertNotNull(netInfo); } diff --git a/src/test/java/io/bytom/integration/UTXOTest.java b/src/test/java/io/bytom/integration/UTXOTest.java index 2252e91..aca21dc 100644 --- a/src/test/java/io/bytom/integration/UTXOTest.java +++ b/src/test/java/io/bytom/integration/UTXOTest.java @@ -1,7 +1,6 @@ package io.bytom.integration; import io.bytom.TestUtils; -import io.bytom.api.Balance; import io.bytom.api.UnspentOutput; import io.bytom.exception.BytomException; import io.bytom.http.Client; -- 2.11.0