OSDN Git Service

bdc74572e6802493a64ba45728b3797d80797f46
[bytom/bytom-java-sdk.git] / java-sdk / src / main / java / io / bytom / api / CoreConfig.java
1 package io.bytom.api;
2
3 import com.google.gson.annotations.SerializedName;
4 import io.bytom.common.Utils;
5 import io.bytom.exception.BytomException;
6 import io.bytom.http.Client;
7 import org.apache.log4j.Logger;
8
9 public class CoreConfig {
10
11
12     private static Logger logger = Logger.getLogger(CoreConfig.class);
13
14     /**
15      * Call net-info api
16      *
17      * @param client
18      * @return
19      * @throws BytomException
20      */
21     public static NetInfo getNetInfo(Client client) throws BytomException {
22         NetInfo netInfo = client.request("net-info", null, NetInfo.class);
23
24         logger.info("net-info:");
25         logger.info(netInfo.toJson());
26
27         return netInfo;
28     }
29
30     /**
31      * Call gas-rate api
32      *
33      * @param client
34      * @return
35      * @throws BytomException
36      */
37     public static Integer getGasRate(Client client) throws BytomException {
38         Integer gas = client.requestGet("gas-rate", null, "gas_rate", Integer.class);
39
40         logger.info("gas-rate:");
41         logger.info(gas);
42
43         return gas;
44     }
45
46     public static class NetInfo {
47         /**
48          * listening, whether the node is listening.
49          */
50         public boolean listening;
51
52         /**
53          * syncing, whether the node is syncing.
54          */
55         public boolean syncing;
56
57         /**
58          * mining, whether the node is mining.
59          */
60         public boolean mining;
61
62         /**
63          * nodeXPub, the node xpub.
64          */
65         @SerializedName("node_xpub")
66         public String nodeXPub;
67
68         /**
69          * peer_count, current count of connected peers.
70          */
71         @SerializedName("peer_count")
72         public int peerCount;
73
74         /**
75          * current_block, current block height in the node's blockchain.
76          */
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;
91
92         /**
93          * network_id, network id.
94          */
95         @SerializedName("network_id")
96         public String networkID;
97
98         /**
99          * version, bytom version.
100          */
101         @SerializedName("version")
102         public String version;
103
104         public String toJson() {
105             return Utils.serializer.toJson(this);
106         }
107     }
108 }