added node syncing endpoint

This commit is contained in:
Fabian 2018-03-08 14:39:59 +01:00 committed by Ethan Buchman
parent 7d36d953f2
commit 37bbde837b
2 changed files with 21 additions and 3 deletions

View File

@ -48,7 +48,8 @@ func startRESTServer(cdc *wire.Codec) func(cmd *cobra.Command, args []string) er
func initRouter(cdc *wire.Codec) http.Handler {
r := mux.NewRouter()
r.HandleFunc("/version", version.VersionRequestHandler).Methods("GET")
r.HandleFunc("/node_info", rpc.NodeStatusRequestHandler).Methods("GET")
r.HandleFunc("/node_info", rpc.NodeInfoRequestHandler).Methods("GET")
r.HandleFunc("/syncing", rpc.NodeSyncingRequestHandler).Methods("GET")
r.HandleFunc("/keys", keys.QueryKeysRequestHandler).Methods("GET")
r.HandleFunc("/keys", keys.AddNewKeyRequestHandler).Methods("POST")
r.HandleFunc("/keys/seed", keys.SeedRequestHandler).Methods("GET")

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"github.com/spf13/cobra"
wire "github.com/tendermint/go-wire"
@ -51,8 +52,7 @@ func printNodeStatus(cmd *cobra.Command, args []string) error {
// REST
// TODO match desired spec output
func NodeStatusRequestHandler(w http.ResponseWriter, r *http.Request) {
func NodeInfoRequestHandler(w http.ResponseWriter, r *http.Request) {
status, err := getNodeStatus()
if err != nil {
w.WriteHeader(500)
@ -69,3 +69,20 @@ func NodeStatusRequestHandler(w http.ResponseWriter, r *http.Request) {
}
w.Write(output)
}
func NodeSyncingRequestHandler(w http.ResponseWriter, r *http.Request) {
status, err := getNodeStatus()
if err != nil {
w.WriteHeader(500)
w.Write([]byte(err.Error()))
return
}
syncing := status.Syncing
if err != nil {
w.WriteHeader(500)
w.Write([]byte(err.Error()))
return
}
w.Write([]byte(strconv.FormatBool(syncing)))
}