OSDN Git Service

33e65881c921d5f8579919b8c9c5f7a7ee913c31
[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.offline.common.Utils;
5 import io.bytom.offline.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          * peer_count, current count of connected peers.
64          */
65         @SerializedName("peer_count")
66         public int peerCount;
67
68         /**
69          * current_block, current block height in the node's blockchain.
70          */
71         @SerializedName("current_block")
72         public long currentBlock;
73
74         /**
75          * highest_block, current highest block of the connected peers.
76          */
77         @SerializedName("highest_block")
78         public long highestBlock;
79
80         /**
81          * network_id, network id.
82          */
83         @SerializedName("network_id")
84         public String networkID;
85
86         /**
87          * version, bytom version.
88          */
89         @SerializedName("version")
90         public String version;
91
92         public String toJson() {
93             return Utils.serializer.toJson(this);
94         }
95     }
96 }