From d0dc04001e83992033b0a56b708ba0b610beb9b1 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 6 Dec 2017 01:25:11 -0500 Subject: [PATCH] rpc: make time human readable. closes #926 --- rpc/core/status.go | 14 +++++++++----- rpc/core/types/responses.go | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/rpc/core/status.go b/rpc/core/status.go index 4a8d84ece..0cb7acc1f 100644 --- a/rpc/core/status.go +++ b/rpc/core/status.go @@ -1,6 +1,8 @@ package core import ( + "time" + data "github.com/tendermint/go-wire/data" ctypes "github.com/tendermint/tendermint/rpc/core/types" "github.com/tendermint/tendermint/types" @@ -56,18 +58,20 @@ import ( func Status() (*ctypes.ResultStatus, error) { latestHeight := blockStore.Height() var ( - latestBlockMeta *types.BlockMeta - latestBlockHash data.Bytes - latestAppHash data.Bytes - latestBlockTime int64 + latestBlockMeta *types.BlockMeta + latestBlockHash data.Bytes + latestAppHash data.Bytes + latestBlockTimeNano int64 ) if latestHeight != 0 { latestBlockMeta = blockStore.LoadBlockMeta(latestHeight) latestBlockHash = latestBlockMeta.BlockID.Hash latestAppHash = latestBlockMeta.Header.AppHash - latestBlockTime = latestBlockMeta.Header.Time.UnixNano() + latestBlockTimeNano = latestBlockMeta.Header.Time.UnixNano() } + latestBlockTime := time.Unix(0, latestBlockTimeNano) + return &ctypes.ResultStatus{ NodeInfo: p2pSwitch.NodeInfo(), PubKey: pubKey, diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index 2a7e729e9..08ddf6599 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -2,6 +2,7 @@ package core_types import ( "strings" + "time" abci "github.com/tendermint/abci/types" crypto "github.com/tendermint/go-crypto" @@ -52,7 +53,7 @@ type ResultStatus struct { LatestBlockHash data.Bytes `json:"latest_block_hash"` LatestAppHash data.Bytes `json:"latest_app_hash"` LatestBlockHeight int64 `json:"latest_block_height"` - LatestBlockTime int64 `json:"latest_block_time"` // nano + LatestBlockTime time.Time `json:"latest_block_time"` // nano Syncing bool `json:"syncing"` }