diff options
author | João Barbosa <joao.paulo.barbosa@gmail.com> | 2021-07-05 22:39:36 +0100 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2021-07-20 10:43:26 +0100 |
commit | 20edf4bcf61e9fa310c3d7f3cac0c80a04df5364 (patch) | |
tree | 83bc6401ae6570f8b3e2be589c901f62253af34f | |
parent | a62fc35a150da584d39d7cd01ade14bbb5002fb9 (diff) |
rpc: Return block time in getblockchaininfo
-rw-r--r-- | doc/release-notes.md | 2 | ||||
-rw-r--r-- | src/rpc/blockchain.cpp | 4 | ||||
-rwxr-xr-x | test/functional/rpc_blockchain.py | 3 |
3 files changed, 8 insertions, 1 deletions
diff --git a/doc/release-notes.md b/doc/release-notes.md index dc28ccb9ed..013ed891ee 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -197,6 +197,8 @@ Low-level changes RPC --- +- `getblockchaininfo` now returns a new `time` field, that provides the chain tip time. (#22407) + - The RPC server can process a limited number of simultaneous RPC requests. Previously, if this limit was exceeded, the RPC server would respond with [status code 500 (`HTTP_INTERNAL_SERVER_ERROR`)](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_server_errors). diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index b630458f23..faa80b4ee9 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1425,7 +1425,8 @@ RPCHelpMan getblockchaininfo() {RPCResult::Type::NUM, "headers", "the current number of headers we have validated"}, {RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block"}, {RPCResult::Type::NUM, "difficulty", "the current difficulty"}, - {RPCResult::Type::NUM, "mediantime", "median time for the current best block"}, + {RPCResult::Type::NUM_TIME, "time", "The block time expressed in " + UNIX_EPOCH_TIME}, + {RPCResult::Type::NUM_TIME, "mediantime", "The median block time expressed in " + UNIX_EPOCH_TIME}, {RPCResult::Type::NUM, "verificationprogress", "estimate of verification progress [0..1]"}, {RPCResult::Type::BOOL, "initialblockdownload", "(debug information) estimate of whether this node is in Initial Block Download mode"}, {RPCResult::Type::STR_HEX, "chainwork", "total amount of work in active chain, in hexadecimal"}, @@ -1481,6 +1482,7 @@ RPCHelpMan getblockchaininfo() obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1); obj.pushKV("bestblockhash", tip->GetBlockHash().GetHex()); obj.pushKV("difficulty", (double)GetDifficulty(tip)); + obj.pushKV("time", (int64_t)tip->nTime); obj.pushKV("mediantime", (int64_t)tip->GetMedianTimePast()); obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), tip)); obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload()); diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index 90715cae26..f7290ff229 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -93,11 +93,14 @@ class BlockchainTest(BitcoinTestFramework): 'pruned', 'size_on_disk', 'softforks', + 'time', 'verificationprogress', 'warnings', ] res = self.nodes[0].getblockchaininfo() + assert isinstance(res['time'], int) + # result should have these additional pruning keys if manual pruning is enabled assert_equal(sorted(res.keys()), sorted(['pruneheight', 'automatic_pruning'] + keys)) |