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.

59 lines
1.7 KiB

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