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.

68 lines
1.8 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.ResultStatus, 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.ResultStatus{
  29. NodeInfo: p2pSwitch.NodeInfo(),
  30. GenesisHash: genesisHash,
  31. PubKey: privValidator.PubKey,
  32. LatestBlockHash: latestBlockHash,
  33. LatestBlockHeight: latestHeight,
  34. LatestBlockTime: latestBlockTime}, nil
  35. }
  36. //-----------------------------------------------------------------------------
  37. func NetInfo() (*ctypes.ResultNetInfo, error) {
  38. listening := p2pSwitch.IsListening()
  39. listeners := []string{}
  40. for _, listener := range p2pSwitch.Listeners() {
  41. listeners = append(listeners, listener.String())
  42. }
  43. peers := []ctypes.Peer{}
  44. for _, peer := range p2pSwitch.Peers().List() {
  45. peers = append(peers, ctypes.Peer{
  46. NodeInfo: *peer.NodeInfo,
  47. IsOutbound: peer.IsOutbound(),
  48. })
  49. }
  50. return &ctypes.ResultNetInfo{
  51. Listening: listening,
  52. Listeners: listeners,
  53. Peers: peers,
  54. }, nil
  55. }
  56. //-----------------------------------------------------------------------------
  57. func Genesis() (*ctypes.ResultGenesis, error) {
  58. return &ctypes.ResultGenesis{genDoc}, nil
  59. }