From 9b6de3901eff801ccc26026e3b573784ff292917 Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Wed, 23 May 2018 10:59:27 +0200 Subject: [PATCH] Add internal state information to index page --- server/socketio.go | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/server/socketio.go b/server/socketio.go index cce86e75..3ea084d4 100644 --- a/server/socketio.go +++ b/server/socketio.go @@ -132,15 +132,46 @@ func (s *SocketIoServer) txRedirect(w http.ResponseWriter, r *http.Request) { } } +type resAboutBlockbookPublic struct { + Coin string `json:"coin"` + About string `json:"about"` + Version string `json:"version"` + GitCommit string `json:"gitcommit"` + BuildTime string `json:"buildtime"` + InSync bool `json:"inSync"` + BestHeight uint32 `json:"bestHeight"` + LastBlockTime time.Time `json:"lastBlockTime"` + InSyncMempool bool `json:"inSyncMempool"` + LastMempoolTime time.Time `json:"lastMempoolTime"` +} + func (s *SocketIoServer) index(w http.ResponseWriter, r *http.Request) { - w.Write([]byte(blockbookAbout)) + vi := common.GetVersionInfo() + ss, bh, st := common.IS.GetSyncState() + ms, mt := common.IS.GetMempoolSyncState() + a := resAboutBlockbookPublic{ + Coin: common.IS.Coin, + About: blockbookAbout, + Version: vi.Version, + GitCommit: vi.GitCommit, + BuildTime: vi.BuildTime, + InSync: ss, + BestHeight: bh, + LastBlockTime: st, + InSyncMempool: ms, + LastMempoolTime: mt, + } + buf, err := json.MarshalIndent(a, "", " ") + if err != nil { + glog.Error(err) + } + w.Write(buf) } func (s *SocketIoServer) apiBlockIndex(w http.ResponseWriter, r *http.Request) { type resBlockIndex struct { BlockHash string `json:"blockHash"` About string `json:"about"` - common.VersionInfo } var err error var hash string @@ -159,9 +190,8 @@ func (s *SocketIoServer) apiBlockIndex(w http.ResponseWriter, r *http.Request) { glog.Error(err) } else { r := resBlockIndex{ - BlockHash: hash, - About: blockbookAbout, - VersionInfo: common.GetVersionInfo(), + BlockHash: hash, + About: blockbookAbout, } json.NewEncoder(w).Encode(r) }