• R/O
  • HTTP
  • SSH
  • HTTPS

bytom-java-sdk: Commit

Official Java SDK for Bytom


Commit MetaInfo

Révisionbdaa5ff1b2962fe2ee44ad1f649c2e09240c2242 (tree)
l'heure2021-07-30 17:08:14
Auteurdoraemon <wyjDoraemon@163....>
Commiterdoraemon

Message de Log

add chain-status api

Change Summary

Modification

--- a/java-sdk/src/main/java/io/bytom/api/CoreConfig.java
+++ b/java-sdk/src/main/java/io/bytom/api/CoreConfig.java
@@ -72,22 +72,10 @@ public class CoreConfig {
7272 public int peerCount;
7373
7474 /**
75- * current_block, current block height in the node's blockchain.
75+ * highest_height, current highest block of the connected peers.
7676 */
77- @SerializedName("current_block")
78- public long currentBlock;
79-
80- /**
81- * highest_block, current highest block of the connected peers.
82- */
83- @SerializedName("highest_block")
84- public long highestBlock;
85-
86- /**
87- * finalized_block, finalized block of the connected peers.
88- */
89- @SerializedName("finalized_block")
90- public long finalizedBlock;
77+ @SerializedName("highest_height")
78+ public long highestHeight;
9179
9280 /**
9381 * network_id, network id.
@@ -105,4 +93,62 @@ public class CoreConfig {
10593 return Utils.serializer.toJson(this);
10694 }
10795 }
96+
97+ /**
98+ * Call chain-status api
99+ *
100+ * @param client
101+ * @return
102+ * @throws BytomException
103+ */
104+ public static ChainStatus getChainStatus(Client client) throws BytomException {
105+ ChainStatus chainStatus = client.request("chain-status", null, ChainStatus.class);
106+
107+ logger.info("chain-status:");
108+ logger.info(chainStatus.toJson());
109+
110+ return chainStatus;
111+ }
112+
113+ public static class ChainStatus {
114+ /**
115+ * current_height, current block height in the node's blockchain.
116+ */
117+ @SerializedName("current_height")
118+ public long currentHeight;
119+
120+ /**
121+ * current_hash, current block hash in the node's blockchain.
122+ */
123+ @SerializedName("current_hash")
124+ public String currentHash;
125+
126+ /**
127+ * finalized_height, finalized block height in the node's blockchain.
128+ */
129+ @SerializedName("finalized_height")
130+ public long finalizedHeight;
131+
132+ /**
133+ * finalized_hash, finalized block hash in the node's blockchain.
134+ */
135+ @SerializedName("finalized_hash")
136+ public String finalizedHash;
137+
138+ /**
139+ * justified_height, justified block height in the node's blockchain.
140+ */
141+ @SerializedName("justified_height")
142+ public long justifiedHeight;
143+
144+ /**
145+ * justified_hash, justified block hash in the node's blockchain.
146+ */
147+ @SerializedName("justified_hash")
148+ public String justifiedHash;
149+
150+ public String toJson() {
151+ return Utils.serializer.toJson(this);
152+ }
153+ }
108154 }
--- a/java-sdk/src/test/java/io/bytom/integration/CoreConfigTest.java
+++ b/java-sdk/src/test/java/io/bytom/integration/CoreConfigTest.java
@@ -30,6 +30,12 @@ public class CoreConfigTest {
3030 }
3131
3232 @Test
33+ public void testChainStatus() throws Exception {
34+ CoreConfig.ChainStatus chainStatus = CoreConfig.getChainStatus(client);
35+ Assert.assertNotNull(chainStatus);
36+ }
37+
38+ @Test
3339 public void testGasRate() throws Exception {
3440 gasRate = CoreConfig.getGasRate(client);
3541 Assert.assertNotNull(gasRate);
Afficher sur ancien navigateur de dépôt.