mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-29 12:41:44 +00:00
rpc: add status and net info
This commit is contained in:
33
rpc/net.go
Normal file
33
rpc/net.go
Normal file
@ -0,0 +1,33 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"github.com/tendermint/tendermint/config"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func StatusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
genesisHash := blockStore.LoadBlockMeta(0).Hash
|
||||
latestHeight := blockStore.Height()
|
||||
latestBlockMeta := blockStore.LoadBlockMeta(latestHeight)
|
||||
latestBlockHash := latestBlockMeta.Hash
|
||||
latestBlockTime := latestBlockMeta.Header.Time.UnixNano()
|
||||
WriteAPIResponse(w, API_OK, struct {
|
||||
GenesisHash []byte
|
||||
LatestBlockHash []byte
|
||||
LatestBlockHeight uint
|
||||
LatestBlockTime int64 // nano
|
||||
Network string
|
||||
}{genesisHash, latestBlockHash, latestHeight, latestBlockTime, config.App.GetString("Network")})
|
||||
}
|
||||
|
||||
func NetInfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
o, i, _ := p2pSwitch.NumPeers()
|
||||
numPeers := o + i
|
||||
listening := p2pSwitch.IsListening()
|
||||
network := config.App.GetString("Network")
|
||||
WriteAPIResponse(w, API_OK, struct {
|
||||
NumPeers int
|
||||
Listening bool
|
||||
Network string
|
||||
}{numPeers, listening, network})
|
||||
}
|
Reference in New Issue
Block a user