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.

73 lines
2.1 KiB

  1. package core
  2. import (
  3. "io/ioutil"
  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.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.GetString("moniker"),
  27. ChainID: config.GetString("chain_id"),
  28. Version: config.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. }
  55. //-----------------------------------------------------------------------------
  56. // returns pointer because the rpc-gen code returns nil (TODO!)
  57. func Genesis() (*string, error) {
  58. b, err := ioutil.ReadFile(config.GetString("genesis_file"))
  59. if err != nil {
  60. return nil, err
  61. }
  62. ret := string(b)
  63. return &ret, nil
  64. }