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.

56 lines
1.7 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. moniker := config.App().GetString("Moniker")
  31. network := config.App().GetString("Network")
  32. listeners := []string{}
  33. for _, listener := range p2pSwitch.Listeners() {
  34. listeners = append(listeners, listener.String())
  35. }
  36. peers := []ctypes.Peer{}
  37. for _, peer := range p2pSwitch.Peers().List() {
  38. peers = append(peers, ctypes.Peer{
  39. NodeInfo: *peer.NodeInfo,
  40. IsOutbound: peer.IsOutbound(),
  41. })
  42. }
  43. return &ctypes.ResponseNetInfo{
  44. Moniker: moniker,
  45. Network: network,
  46. Listening: listening,
  47. Listeners: listeners,
  48. Peers: peers,
  49. }, nil
  50. }