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.

83 lines
2.2 KiB

  1. package core
  2. import (
  3. "time"
  4. ctypes "github.com/tendermint/tendermint/rpc/core/types"
  5. "github.com/tendermint/tendermint/types"
  6. cmn "github.com/tendermint/tmlibs/common"
  7. )
  8. // Get Tendermint status including node info, pubkey, latest block
  9. // hash, app hash, block height and time.
  10. //
  11. // ```shell
  12. // curl 'localhost:46657/status'
  13. // ```
  14. //
  15. // ```go
  16. // client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket")
  17. // result, err := client.Status()
  18. // ```
  19. //
  20. // > The above command returns JSON structured like this:
  21. //
  22. // ```json
  23. // {
  24. // "result": {
  25. // "syncing": false,
  26. // "latest_block_time": "2017-12-07T18:19:47.617Z",
  27. // "latest_block_height": 6,
  28. // "latest_app_hash": "",
  29. // "latest_block_hash": "A63D0C3307DEDCCFCC82ED411AE9108B70B29E02",
  30. // "pub_key": {
  31. // "data": "8C9A68070CBE33F9C445862BA1E9D96A75CEB68C0CF6ADD3652D07DCAC5D0380",
  32. // "type": "ed25519"
  33. // },
  34. // "node_info": {
  35. // "other": [
  36. // "wire_version=0.7.2",
  37. // "p2p_version=0.5.0",
  38. // "consensus_version=v1/0.2.2",
  39. // "rpc_version=0.7.0/3",
  40. // "tx_index=on",
  41. // "rpc_addr=tcp://0.0.0.0:46657"
  42. // ],
  43. // "version": "0.13.0-14ccc8b",
  44. // "listen_addr": "10.0.2.15:46656",
  45. // "remote_addr": "",
  46. // "network": "test-chain-qhVCa2",
  47. // "moniker": "vagrant-ubuntu-trusty-64",
  48. // "pub_key": "844981FE99ABB19F7816F2D5E94E8A74276AB1153760A7799E925C75401856C6"
  49. // }
  50. // },
  51. // "id": "",
  52. // "jsonrpc": "2.0"
  53. // }
  54. // ```
  55. func Status() (*ctypes.ResultStatus, error) {
  56. latestHeight := blockStore.Height()
  57. var (
  58. latestBlockMeta *types.BlockMeta
  59. latestBlockHash cmn.HexBytes
  60. latestAppHash cmn.HexBytes
  61. latestBlockTimeNano int64
  62. )
  63. if latestHeight != 0 {
  64. latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
  65. latestBlockHash = latestBlockMeta.BlockID.Hash
  66. latestAppHash = latestBlockMeta.Header.AppHash
  67. latestBlockTimeNano = latestBlockMeta.Header.Time.UnixNano()
  68. }
  69. latestBlockTime := time.Unix(0, latestBlockTimeNano)
  70. return &ctypes.ResultStatus{
  71. NodeInfo: p2pSwitch.NodeInfo(),
  72. PubKey: pubKey,
  73. LatestBlockHash: latestBlockHash,
  74. LatestAppHash: latestAppHash,
  75. LatestBlockHeight: latestHeight,
  76. LatestBlockTime: latestBlockTime,
  77. Syncing: consensusReactor.FastSync()}, nil
  78. }