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.

60 lines
1.8 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("genesis_file"))
  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{
  26. Moniker: config.App().GetString("moniker"),
  27. Network: config.App().GetString("network"),
  28. Version: config.App().GetString("version"),
  29. GenesisHash: genesisHash,
  30. PubKey: privValidator.PubKey,
  31. LatestBlockHash: latestBlockHash,
  32. LatestBlockHeight: latestHeight,
  33. LatestBlockTime: latestBlockTime}, nil
  34. }
  35. //-----------------------------------------------------------------------------
  36. func NetInfo() (*ctypes.ResponseNetInfo, error) {
  37. listening := p2pSwitch.IsListening()
  38. listeners := []string{}
  39. for _, listener := range p2pSwitch.Listeners() {
  40. listeners = append(listeners, listener.String())
  41. }
  42. peers := []ctypes.Peer{}
  43. for _, peer := range p2pSwitch.Peers().List() {
  44. peers = append(peers, ctypes.Peer{
  45. NodeInfo: *peer.NodeInfo,
  46. IsOutbound: peer.IsOutbound(),
  47. })
  48. }
  49. return &ctypes.ResponseNetInfo{
  50. Listening: listening,
  51. Listeners: listeners,
  52. Peers: peers,
  53. }, nil
  54. }