2018-02-23 02:25:25 -08:00
|
|
|
package rpc
|
2018-02-22 06:33:34 -08:00
|
|
|
|
2018-02-23 01:49:30 -08:00
|
|
|
import (
|
2018-12-19 08:25:27 -08:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2018-02-22 06:33:34 -08:00
|
|
|
|
2018-12-19 08:25:27 -08:00
|
|
|
"github.com/gorilla/mux"
|
2018-12-10 06:27:25 -08:00
|
|
|
|
2018-04-25 07:49:31 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/context"
|
2018-12-19 08:25:27 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/utils"
|
|
|
|
"github.com/cosmos/cosmos-sdk/version"
|
2018-02-23 01:49:30 -08:00
|
|
|
)
|
2018-02-22 06:33:34 -08:00
|
|
|
|
2018-04-18 21:49:24 -07:00
|
|
|
// Register REST endpoints
|
2018-08-06 11:11:30 -07:00
|
|
|
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
2018-12-19 08:25:27 -08:00
|
|
|
r.HandleFunc("/version", CLIVersionRequestHandler).Methods("GET")
|
|
|
|
r.HandleFunc("/node_version", NodeVersionRequestHandler(cliCtx)).Methods("GET")
|
2018-08-06 11:11:30 -07:00
|
|
|
r.HandleFunc("/node_info", NodeInfoRequestHandlerFn(cliCtx)).Methods("GET")
|
|
|
|
r.HandleFunc("/syncing", NodeSyncingRequestHandlerFn(cliCtx)).Methods("GET")
|
|
|
|
r.HandleFunc("/blocks/latest", LatestBlockRequestHandlerFn(cliCtx)).Methods("GET")
|
|
|
|
r.HandleFunc("/blocks/{height}", BlockRequestHandlerFn(cliCtx)).Methods("GET")
|
|
|
|
r.HandleFunc("/validatorsets/latest", LatestValidatorSetRequestHandlerFn(cliCtx)).Methods("GET")
|
|
|
|
r.HandleFunc("/validatorsets/{height}", ValidatorSetRequestHandlerFn(cliCtx)).Methods("GET")
|
2018-03-09 01:15:56 -08:00
|
|
|
}
|
2018-12-19 08:25:27 -08:00
|
|
|
|
|
|
|
// cli version REST handler endpoint
|
|
|
|
func CLIVersionRequestHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.Write([]byte(fmt.Sprintf("{\"version\": \"%s\"}", version.GetVersion())))
|
|
|
|
}
|
|
|
|
|
|
|
|
// connected node version REST handler endpoint
|
|
|
|
func NodeVersionRequestHandler(cliCtx context.CLIContext) http.HandlerFunc {
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
version, err := cliCtx.Query("/app/version", nil)
|
|
|
|
if err != nil {
|
|
|
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.Write(version)
|
|
|
|
}
|
|
|
|
}
|