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.

70 lines
1.9 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. // cache the genesis state
  10. var genesisState *sm.State
  11. func Status() (*ctypes.ResponseStatus, error) {
  12. db := dbm.NewMemDB()
  13. if genesisState == nil {
  14. genesisState = sm.MakeGenesisState(db, genDoc)
  15. }
  16. genesisHash := genesisState.Hash()
  17. latestHeight := blockStore.Height()
  18. var (
  19. latestBlockMeta *types.BlockMeta
  20. latestBlockHash []byte
  21. latestBlockTime int64
  22. )
  23. if latestHeight != 0 {
  24. latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
  25. latestBlockHash = latestBlockMeta.Hash
  26. latestBlockTime = latestBlockMeta.Header.Time.UnixNano()
  27. }
  28. return &ctypes.ResponseStatus{
  29. Moniker: config.GetString("moniker"),
  30. ChainID: config.GetString("chain_id"),
  31. Version: config.GetString("version"),
  32. GenesisHash: genesisHash,
  33. PubKey: privValidator.PubKey,
  34. LatestBlockHash: latestBlockHash,
  35. LatestBlockHeight: latestHeight,
  36. LatestBlockTime: latestBlockTime}, nil
  37. }
  38. //-----------------------------------------------------------------------------
  39. func NetInfo() (*ctypes.ResponseNetInfo, error) {
  40. listening := p2pSwitch.IsListening()
  41. listeners := []string{}
  42. for _, listener := range p2pSwitch.Listeners() {
  43. listeners = append(listeners, listener.String())
  44. }
  45. peers := []ctypes.Peer{}
  46. for _, peer := range p2pSwitch.Peers().List() {
  47. peers = append(peers, ctypes.Peer{
  48. NodeInfo: *peer.NodeInfo,
  49. IsOutbound: peer.IsOutbound(),
  50. })
  51. }
  52. return &ctypes.ResponseNetInfo{
  53. Listening: listening,
  54. Listeners: listeners,
  55. Peers: peers,
  56. }, nil
  57. }
  58. //-----------------------------------------------------------------------------
  59. func Genesis() (*sm.GenesisDoc, error) {
  60. return genDoc, nil
  61. }