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.

79 lines
2.2 KiB

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