OSDN Git Service

commit java sdk doc and source code
[bytom/bytom-java-sdk.git] / src / main / java / io / bytom / api / NetInfo.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 NetInfo {
10
11     /**
12      * listening, whether the node is listening.
13      */
14     public boolean listening;
15
16     /**
17      * syncing, whether the node is syncing.
18      */
19     public boolean syncing;
20
21     /**
22      * mining, whether the node is mining.
23      */
24     public boolean mining;
25
26     /**
27      * peer_count, current count of connected peers.
28      */
29     @SerializedName("peer_count")
30     public int peerCount;
31
32     /**
33      * current_block, current block height in the node's blockchain.
34      */
35     @SerializedName("current_block")
36     public long currentBlock;
37
38     /**
39      * highest_block, current highest block of the connected peers.
40      */
41     @SerializedName("highest_block")
42     public long highestBlock;
43
44     /**
45      * network_id, network id.
46      */
47     @SerializedName("network_id")
48     public String networkID;
49
50     /**
51      * version, bytom version.
52      */
53     @SerializedName("version")
54     public String version;
55
56     private static Logger logger = Logger.getLogger(NetInfo.class);
57
58     public String toJson() {
59         return Utils.serializer.toJson(this);
60     }
61
62     /**
63      * Call net-info api
64      *
65      * @param client
66      * @return
67      * @throws BytomException
68      */
69     public static NetInfo getNetInfo(Client client) throws BytomException {
70         NetInfo netInfo = client.request("net-info", null, NetInfo.class);
71
72         logger.info("net-info:");
73         logger.info(netInfo.toJson());
74         return netInfo;
75     }
76 }