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.

51 lines
1.5 KiB

  1. package core
  2. import (
  3. "github.com/tendermint/tendermint/config"
  4. dbm "github.com/tendermint/tendermint/db"
  5. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  6. sm "github.com/tendermint/tendermint/state"
  7. "github.com/tendermint/tendermint/types"
  8. )
  9. //-----------------------------------------------------------------------------
  10. func Status() (*ctypes.ResponseStatus, error) {
  11. db := dbm.NewMemDB()
  12. genesisState := sm.MakeGenesisStateFromFile(db, config.App().GetString("GenesisFile"))
  13. genesisHash := genesisState.Hash()
  14. latestHeight := blockStore.Height()
  15. var (
  16. latestBlockMeta *types.BlockMeta
  17. latestBlockHash []byte
  18. latestBlockTime int64
  19. )
  20. if latestHeight != 0 {
  21. latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
  22. latestBlockHash = latestBlockMeta.Hash
  23. latestBlockTime = latestBlockMeta.Header.Time.UnixNano()
  24. }
  25. return &ctypes.ResponseStatus{genesisHash, config.App().GetString("Network"), latestBlockHash, latestHeight, latestBlockTime}, nil
  26. }
  27. //-----------------------------------------------------------------------------
  28. func NetInfo() (*ctypes.ResponseNetInfo, error) {
  29. listening := p2pSwitch.IsListening()
  30. network := config.App().GetString("Network")
  31. listeners := []string{}
  32. for _, listener := range p2pSwitch.Listeners() {
  33. listeners = append(listeners, listener.String())
  34. }
  35. peers := []string{}
  36. for _, peer := range p2pSwitch.Peers().List() {
  37. peers = append(peers, peer.String())
  38. }
  39. return &ctypes.ResponseNetInfo{
  40. Network: network,
  41. Listening: listening,
  42. Listeners: listeners,
  43. Peers: peers,
  44. }, nil
  45. }