@@ -2,9 +2,7 @@ package rpc
2
2
3
3
import (
4
4
"fmt"
5
- "log"
6
5
"net/http"
7
- "strconv"
8
6
9
7
"github.com/spf13/cobra"
10
8
"github.com/spf13/viper"
@@ -15,9 +13,12 @@ import (
15
13
"github.com/cosmos/cosmos-sdk/client/flags"
16
14
"github.com/cosmos/cosmos-sdk/codec"
17
15
"github.com/cosmos/cosmos-sdk/types/rest"
16
+ "github.com/cosmos/cosmos-sdk/version"
17
+
18
+ "github.com/tendermint/tendermint/p2p"
18
19
)
19
20
20
- // StatusCommand returns the status of the network
21
+ // StatusCommand returns the command to return the status of the network.
21
22
func StatusCommand () * cobra.Command {
22
23
cmd := & cobra.Command {
23
24
Use : "status" ,
@@ -32,7 +33,6 @@ func StatusCommand() *cobra.Command {
32
33
}
33
34
34
35
func getNodeStatus (cliCtx context.CLIContext ) (* ctypes.ResultStatus , error ) {
35
- // get the node
36
36
node , err := cliCtx .GetNode ()
37
37
if err != nil {
38
38
return & ctypes.ResultStatus {}, err
@@ -41,9 +41,7 @@ func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) {
41
41
return node .Status ()
42
42
}
43
43
44
- // CMD
45
-
46
- func printNodeStatus (cmd * cobra.Command , args []string ) error {
44
+ func printNodeStatus (_ * cobra.Command , _ []string ) error {
47
45
// No need to verify proof in getting node status
48
46
viper .Set (flags .FlagTrustNode , true )
49
47
cliCtx := context .NewCLIContext ()
@@ -66,7 +64,11 @@ func printNodeStatus(cmd *cobra.Command, args []string) error {
66
64
return nil
67
65
}
68
66
69
- // REST
67
+ type nodeInfoResponse struct {
68
+ p2p.DefaultNodeInfo `json:"node_info"`
69
+
70
+ ApplicationVersion version.Info `json:"application_version"`
71
+ }
70
72
71
73
// REST handler for node info
72
74
func NodeInfoRequestHandlerFn (cliCtx context.CLIContext ) http.HandlerFunc {
@@ -77,11 +79,18 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
77
79
return
78
80
}
79
81
80
- nodeInfo := status .NodeInfo
81
- rest .PostProcessResponse (w , cliCtx , nodeInfo )
82
+ resp := nodeInfoResponse {
83
+ DefaultNodeInfo : status .NodeInfo ,
84
+ ApplicationVersion : version .NewInfo (),
85
+ }
86
+ rest .PostProcessResponseBare (w , cliCtx , resp )
82
87
}
83
88
}
84
89
90
+ type syncingResponse struct {
91
+ Syncing bool `json:"syncing"`
92
+ }
93
+
85
94
// REST handler for node syncing
86
95
func NodeSyncingRequestHandlerFn (cliCtx context.CLIContext ) http.HandlerFunc {
87
96
return func (w http.ResponseWriter , r * http.Request ) {
@@ -91,9 +100,6 @@ func NodeSyncingRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
91
100
return
92
101
}
93
102
94
- syncing := status .SyncInfo .CatchingUp
95
- if _ , err := w .Write ([]byte (strconv .FormatBool (syncing ))); err != nil {
96
- log .Printf ("could not write response: %v" , err )
97
- }
103
+ rest .PostProcessResponseBare (w , cliCtx , syncingResponse {Syncing : status .SyncInfo .CatchingUp })
98
104
}
99
105
}
0 commit comments