tendermint/rpc/core/status.go

80 lines
2.2 KiB
Go
Raw Normal View History

2015-12-21 15:13:42 -08:00
package core
import (
2017-04-21 15:13:25 -07:00
data "github.com/tendermint/go-wire/data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
2015-12-21 15:13:42 -08:00
"github.com/tendermint/tendermint/types"
)
// Get Tendermint status including node info, pubkey, latest block
// hash, app hash, block height and time.
//
// ```shell
// curl 'localhost:46657/status'
// ```
//
// ```go
// client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket")
// result, err := client.Status()
// ```
//
// > The above command returns JSON structured like this:
//
// ```json
// {
// "error": "",
// "result": {
// "latest_block_time": 1.49631773695e+18,
// "latest_block_height": 22924,
// "latest_app_hash": "9D16177BC71E445476174622EA559715C293740C",
// "latest_block_hash": "75B36EEF96C277A592D8B14867098C58F68BB180",
// "pub_key": {
// "data": "68DFDA7E50F82946E7E8546BED37944A422CD1B831E70DF66BA3B8430593944D",
// "type": "ed25519"
// },
// "node_info": {
// "other": [
// "wire_version=0.6.2",
// "p2p_version=0.5.0",
// "consensus_version=v1/0.2.2",
// "rpc_version=0.7.0/3",
// "tx_index=on",
// "rpc_addr=tcp://0.0.0.0:46657"
// ],
// "version": "0.10.0-rc1-aa22bd84",
// "listen_addr": "10.0.2.15:46656",
// "remote_addr": "",
// "network": "test-chain-6UTNIN",
// "moniker": "anonymous",
// "pub_key": "659B9E54DD6EF9FEF28FAD40629AF0E4BD3C2563BB037132B054A176E00F1D94"
// }
// },
// "id": "",
// "jsonrpc": "2.0"
// }
// ```
2015-12-21 15:13:42 -08:00
func Status() (*ctypes.ResultStatus, error) {
latestHeight := blockStore.Height()
var (
latestBlockMeta *types.BlockMeta
2017-03-22 12:13:18 -07:00
latestBlockHash data.Bytes
latestAppHash data.Bytes
2015-12-21 15:13:42 -08:00
latestBlockTime int64
)
if latestHeight != 0 {
latestBlockMeta = blockStore.LoadBlockMeta(latestHeight)
2017-02-14 12:33:14 -08:00
latestBlockHash = latestBlockMeta.BlockID.Hash
2015-12-21 15:13:42 -08:00
latestAppHash = latestBlockMeta.Header.AppHash
latestBlockTime = latestBlockMeta.Header.Time.UnixNano()
}
return &ctypes.ResultStatus{
NodeInfo: p2pSwitch.NodeInfo(),
2016-10-14 18:36:42 -07:00
PubKey: pubKey,
2015-12-21 15:13:42 -08:00
LatestBlockHash: latestBlockHash,
LatestAppHash: latestAppHash,
LatestBlockHeight: latestHeight,
LatestBlockTime: latestBlockTime,
2017-07-16 23:44:23 -07:00
Syncing: consensusReactor.FastSync()}, nil
2015-12-21 15:13:42 -08:00
}