Merge PR #4837: Cleanup node_info Endpoint

This commit is contained in:
Alexander Bezobchuk
2019-08-02 11:52:55 -04:00
committed by GitHub
parent c4e3578087
commit 451535bd79
10 changed files with 134 additions and 116 deletions
-2
View File
@@ -94,8 +94,6 @@ var (
BlockRequestHandlerFn = rpc.BlockRequestHandlerFn
LatestBlockRequestHandlerFn = rpc.LatestBlockRequestHandlerFn
RegisterRPCRoutes = rpc.RegisterRPCRoutes
CLIVersionRequestHandler = rpc.CLIVersionRequestHandler
NodeVersionRequestHandler = rpc.NodeVersionRequestHandler
StatusCommand = rpc.StatusCommand
NodeInfoRequestHandlerFn = rpc.NodeInfoRequestHandlerFn
NodeSyncingRequestHandlerFn = rpc.NodeSyncingRequestHandlerFn
File diff suppressed because one or more lines are too long
+58 -42
View File
@@ -35,15 +35,6 @@ securityDefinitions:
kms:
type: basic
paths:
/version:
get:
summary: Version of Gaia-lite
tags:
- Misc
description: Get the version of gaia-lite running locally to compare against expected
responses:
200:
description: Plaintext version i.e. "v0.25.0"
/node_info:
get:
description: Information about the connected node
@@ -58,44 +49,62 @@ paths:
schema:
type: object
properties:
id:
type: string
moniker:
type: string
example: validator-name
protocol_version:
application_version:
properties:
p2p:
build_tags:
type: string
example: 7
block:
client_name:
type: string
example: 10
app:
commit:
type: string
example: 0
network:
type: string
example: gaia-2
channels:
type: string
listen_addr:
type: string
example: 192.168.56.1:26656
version:
description: Tendermint version
type: string
example: 0.15.0
other:
description: more information on versions
type: object
go:
type: string
name:
type: string
server_name:
type: string
version:
type: string
node_info:
properties:
tx_index:
id:
type: string
example: on
rpc_address:
moniker:
type: string
example: tcp://0.0.0.0:26657
example: validator-name
protocol_version:
properties:
p2p:
type: string
example: 7
block:
type: string
example: 10
app:
type: string
example: 0
network:
type: string
example: gaia-2
channels:
type: string
listen_addr:
type: string
example: 192.168.56.1:26656
version:
description: Tendermint version
type: string
example: 0.15.0
other:
description: more information on versions
type: object
properties:
tx_index:
type: string
example: on
rpc_address:
type: string
example: tcp://0.0.0.0:26657
500:
description: Failed to query node status
/syncing:
@@ -104,9 +113,16 @@ paths:
tags:
- Tendermint RPC
description: Get if the node is currently syning with other nodes
produces:
- application/json
responses:
200:
description: '"true" or "false"'
description: Node syncing status
schema:
type: object
properties:
syncing:
type: boolean
500:
description: Server internal error
/blocks/latest:
@@ -2481,4 +2497,4 @@ definitions:
total:
type: array
items:
$ref: "#/definitions/Coin"
$ref: "#/definitions/Coin"
-32
View File
@@ -1,21 +1,13 @@
package rpc
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/version"
)
// Register REST endpoints
func RegisterRPCRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/version", CLIVersionRequestHandler).Methods("GET")
r.HandleFunc("/node_version", NodeVersionRequestHandler(cliCtx)).Methods("GET")
r.HandleFunc("/node_info", NodeInfoRequestHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/syncing", NodeSyncingRequestHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/blocks/latest", LatestBlockRequestHandlerFn(cliCtx)).Methods("GET")
@@ -23,27 +15,3 @@ func RegisterRPCRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc("/validatorsets/latest", LatestValidatorSetRequestHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc("/validatorsets/{height}", ValidatorSetRequestHandlerFn(cliCtx)).Methods("GET")
}
// cli version REST handler endpoint
func CLIVersionRequestHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if _, err := w.Write([]byte(fmt.Sprintf("{\"version\": \"%s\"}", version.Version))); err != nil {
log.Printf("could not write response: %v", err)
}
}
// connected node version REST handler endpoint
func NodeVersionRequestHandler(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
res, _, err := cliCtx.Query("/app/version")
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}
w.Header().Set("Content-Type", "application/json")
if _, err := w.Write(res); err != nil {
log.Printf("could not write response: %v", err)
}
}
}
+20 -14
View File
@@ -2,9 +2,7 @@ package rpc
import (
"fmt"
"log"
"net/http"
"strconv"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -15,9 +13,12 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/cosmos/cosmos-sdk/version"
"github.com/tendermint/tendermint/p2p"
)
// StatusCommand returns the status of the network
// StatusCommand returns the command to return the status of the network.
func StatusCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "status",
@@ -32,7 +33,6 @@ func StatusCommand() *cobra.Command {
}
func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) {
// get the node
node, err := cliCtx.GetNode()
if err != nil {
return &ctypes.ResultStatus{}, err
@@ -41,9 +41,7 @@ func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) {
return node.Status()
}
// CMD
func printNodeStatus(cmd *cobra.Command, args []string) error {
func printNodeStatus(_ *cobra.Command, _ []string) error {
// No need to verify proof in getting node status
viper.Set(flags.FlagTrustNode, true)
cliCtx := context.NewCLIContext()
@@ -66,7 +64,11 @@ func printNodeStatus(cmd *cobra.Command, args []string) error {
return nil
}
// REST
type nodeInfoResponse struct {
p2p.DefaultNodeInfo `json:"node_info"`
ApplicationVersion version.Info `json:"application_version"`
}
// REST handler for node info
func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
@@ -77,11 +79,18 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}
nodeInfo := status.NodeInfo
rest.PostProcessResponse(w, cliCtx, nodeInfo)
resp := nodeInfoResponse{
DefaultNodeInfo: status.NodeInfo,
ApplicationVersion: version.NewInfo(),
}
rest.PostProcessResponseBare(w, cliCtx, resp)
}
}
type syncingResponse struct {
Syncing bool `json:"syncing"`
}
// REST handler for node syncing
func NodeSyncingRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
@@ -91,9 +100,6 @@ func NodeSyncingRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return
}
syncing := status.SyncInfo.CatchingUp
if _, err := w.Write([]byte(strconv.FormatBool(syncing))); err != nil {
log.Printf("could not write response: %v", err)
}
rest.PostProcessResponseBare(w, cliCtx, syncingResponse{Syncing: status.SyncInfo.CatchingUp})
}
}