OSDN Git Service

add chain-status api btm2.0
authordoraemon <wyjDoraemon@163.com>
Fri, 30 Jul 2021 08:08:14 +0000 (16:08 +0800)
committerdoraemon <wyjDoraemon@163.com>
Fri, 30 Jul 2021 08:08:14 +0000 (16:08 +0800)
java-sdk/src/main/java/io/bytom/api/CoreConfig.java
java-sdk/src/test/java/io/bytom/integration/CoreConfigTest.java

index bdc7457..babbf92 100644 (file)
@@ -72,22 +72,10 @@ public class CoreConfig {
         public int peerCount;
 
         /**
-         * current_block, current block height in the node's blockchain.
+         * highest_height, current highest block of the connected peers.
          */
-        @SerializedName("current_block")
-        public long currentBlock;
-
-        /**
-         * highest_block, current highest block of the connected peers.
-         */
-        @SerializedName("highest_block")
-        public long highestBlock;
-
-        /**
-         * finalized_block, finalized block of the connected peers.
-         */
-        @SerializedName("finalized_block")
-        public long finalizedBlock;
+        @SerializedName("highest_height")
+        public long highestHeight;
 
         /**
          * network_id, network id.
@@ -105,4 +93,62 @@ public class CoreConfig {
             return Utils.serializer.toJson(this);
         }
     }
+
+    /**
+     * Call chain-status api
+     *
+     * @param client
+     * @return
+     * @throws BytomException
+     */
+    public static ChainStatus getChainStatus(Client client) throws BytomException {
+        ChainStatus chainStatus = client.request("chain-status", null, ChainStatus.class);
+
+        logger.info("chain-status:");
+        logger.info(chainStatus.toJson());
+
+        return chainStatus;
+    }
+
+    public static class ChainStatus {
+        /**
+         * current_height, current block height in the node's blockchain.
+         */
+        @SerializedName("current_height")
+        public long currentHeight;
+
+        /**
+         * current_hash, current block hash in the node's blockchain.
+         */
+        @SerializedName("current_hash")
+        public String currentHash;
+
+        /**
+         * finalized_height, finalized block height in the node's blockchain.
+         */
+        @SerializedName("finalized_height")
+        public long finalizedHeight;
+
+        /**
+         * finalized_hash, finalized block hash in the node's blockchain.
+         */
+        @SerializedName("finalized_hash")
+        public String finalizedHash;
+
+        /**
+         * justified_height, justified block height in the node's blockchain.
+         */
+        @SerializedName("justified_height")
+        public long justifiedHeight;
+
+        /**
+         * justified_hash, justified block hash in the node's blockchain.
+         */
+        @SerializedName("justified_hash")
+        public String justifiedHash;
+
+        public String toJson() {
+            return Utils.serializer.toJson(this);
+        }
+    }
 }
index 943893f..c7607b4 100644 (file)
@@ -30,6 +30,12 @@ public class CoreConfigTest {
     }
 
     @Test
+    public void testChainStatus() throws Exception {
+        CoreConfig.ChainStatus chainStatus = CoreConfig.getChainStatus(client);
+        Assert.assertNotNull(chainStatus);
+    }
+
+    @Test
     public void testGasRate() throws Exception {
         gasRate = CoreConfig.getGasRate(client);
         Assert.assertNotNull(gasRate);