diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 07822b476cb..26b93c920fd 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1299,6 +1299,8 @@ RPCHelpMan getblockchaininfo() {RPCResult::Type::NUM, "blocks", "the height of the most-work fully-validated chain. The genesis block has height 0"}, {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::STR_HEX, "bits", "nBits: compact representation of the block difficulty target"}, + {RPCResult::Type::STR_HEX, "target", "The difficulty target"}, {RPCResult::Type::NUM, "difficulty", "the current difficulty"}, {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}, @@ -1337,6 +1339,8 @@ RPCHelpMan getblockchaininfo() obj.pushKV("blocks", height); obj.pushKV("headers", chainman.m_best_header ? chainman.m_best_header->nHeight : -1); obj.pushKV("bestblockhash", tip.GetBlockHash().GetHex()); + obj.pushKV("bits", strprintf("%08x", tip.nBits)); + obj.pushKV("target", GetTarget(tip, chainman.GetConsensus().powLimit).GetHex()); obj.pushKV("difficulty", GetDifficulty(tip)); obj.pushKV("time", tip.GetBlockTime()); obj.pushKV("mediantime", tip.GetMedianTimePast()); diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py index 3f6a4750b2d..862786affd7 100755 --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -133,6 +133,7 @@ class BlockchainTest(BitcoinTestFramework): keys = [ 'bestblockhash', + 'bits', 'blocks', 'chain', 'chainwork', @@ -142,6 +143,7 @@ class BlockchainTest(BitcoinTestFramework): 'mediantime', 'pruned', 'size_on_disk', + 'target', 'time', 'verificationprogress', 'warnings', @@ -198,6 +200,9 @@ class BlockchainTest(BitcoinTestFramework): assert_equal(res['prune_target_size'], 576716800) assert_greater_than(res['size_on_disk'], 0) + assert_equal(res['bits'], nbits_str(REGTEST_N_BITS)) + assert_equal(res['target'], target_str(REGTEST_TARGET)) + def check_signalling_deploymentinfo_result(self, gdi_result, height, blockhash, status_next): assert height >= 144 and height <= 287