-
Notifications
You must be signed in to change notification settings - Fork 8
/
status.go
80 lines (72 loc) 路 2.16 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package api
import (
"encoding/json"
"time"
)
type StatusResponse struct {
Jsonrpc string `json:"jsonrpc"`
ID string `json:"id,omitempty"`
Result *StatusResult `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
type StatusResult struct {
Version string `json:"version"`
LatestBlockHash string `json:"latest_block_hash"`
LatestAppHash string `json:"latest_app_hash"`
LatestBlockHeight string `json:"latest_block_height"`
LatestBlockTime time.Time `json:"latest_block_time"`
StateHistory string `json:"state_history"`
TmStatus struct {
NodeInfo struct {
ProtocolVersion struct {
P2P string `json:"p2p"`
Block string `json:"block"`
App string `json:"app"`
} `json:"protocol_version"`
ID string `json:"id,omitempty"`
ListenAddr string `json:"listen_addr"`
Network string `json:"network"`
Version string `json:"version"`
Channels string `json:"channels"`
Moniker string `json:"moniker"`
Other struct {
TxIndex string `json:"tx_index"`
RPCAddress string `json:"rpc_address"`
} `json:"other"`
} `json:"node_info"`
SyncInfo struct {
LatestBlockHash string `json:"latest_block_hash"`
LatestAppHash string `json:"latest_app_hash"`
LatestBlockHeight string `json:"latest_block_height"`
LatestBlockTime time.Time `json:"latest_block_time"`
CatchingUp bool `json:"catching_up"`
} `json:"sync_info"`
ValidatorInfo struct {
Address string `json:"address"`
PubKey struct {
Type string `json:"type"`
Value string `json:"value"`
} `json:"pub_key"`
VotingPower string `json:"voting_power"`
} `json:"validator_info"`
} `json:"tm_status"`
}
// Returns node status info.
func (a *Api) Status() (*StatusResult, error) {
res, err := a.client.R().Get("/status")
if err != nil {
return nil, err
}
if res.IsError() {
return nil, NewResponseError(res)
}
response := new(StatusResponse)
err = json.Unmarshal(res.Body(), response)
if err != nil {
return nil, err
}
if response.Error != nil {
return nil, response.Error
}
return response.Result, nil
}