You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
991 B

9 years ago
9 years ago
  1. package rpc
  2. import (
  3. "github.com/tendermint/tendermint/config"
  4. "net/http"
  5. )
  6. func StatusHandler(w http.ResponseWriter, r *http.Request) {
  7. genesisHash := blockStore.LoadBlockMeta(0).Hash
  8. latestHeight := blockStore.Height()
  9. latestBlockMeta := blockStore.LoadBlockMeta(latestHeight)
  10. latestBlockHash := latestBlockMeta.Hash
  11. latestBlockTime := latestBlockMeta.Header.Time.UnixNano()
  12. WriteAPIResponse(w, API_OK, struct {
  13. GenesisHash []byte
  14. LatestBlockHash []byte
  15. LatestBlockHeight uint
  16. LatestBlockTime int64 // nano
  17. Network string
  18. }{genesisHash, latestBlockHash, latestHeight, latestBlockTime, config.App().GetString("Network")})
  19. }
  20. func NetInfoHandler(w http.ResponseWriter, r *http.Request) {
  21. o, i, _ := p2pSwitch.NumPeers()
  22. numPeers := o + i
  23. listening := p2pSwitch.IsListening()
  24. network := config.App().GetString("Network")
  25. WriteAPIResponse(w, API_OK, struct {
  26. NumPeers int
  27. Listening bool
  28. Network string
  29. }{numPeers, listening, network})
  30. }