Skip to content

Commit f153f57

Browse files
committed
rpc: add target and bits to getblockchaininfo
1 parent baa504f commit f153f57

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/rpc/blockchain.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,8 @@ RPCHelpMan getblockchaininfo()
12991299
{RPCResult::Type::NUM, "blocks", "the height of the most-work fully-validated chain. The genesis block has height 0"},
13001300
{RPCResult::Type::NUM, "headers", "the current number of headers we have validated"},
13011301
{RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block"},
1302+
{RPCResult::Type::STR_HEX, "bits", "nBits: compact representation of the block difficulty target"},
1303+
{RPCResult::Type::STR_HEX, "target", "The difficulty target"},
13021304
{RPCResult::Type::NUM, "difficulty", "the current difficulty"},
13031305
{RPCResult::Type::NUM_TIME, "time", "The block time expressed in " + UNIX_EPOCH_TIME},
13041306
{RPCResult::Type::NUM_TIME, "mediantime", "The median block time expressed in " + UNIX_EPOCH_TIME},
@@ -1337,6 +1339,8 @@ RPCHelpMan getblockchaininfo()
13371339
obj.pushKV("blocks", height);
13381340
obj.pushKV("headers", chainman.m_best_header ? chainman.m_best_header->nHeight : -1);
13391341
obj.pushKV("bestblockhash", tip.GetBlockHash().GetHex());
1342+
obj.pushKV("bits", strprintf("%08x", tip.nBits));
1343+
obj.pushKV("target", GetTarget(tip, chainman.GetConsensus().powLimit).GetHex());
13401344
obj.pushKV("difficulty", GetDifficulty(tip));
13411345
obj.pushKV("time", tip.GetBlockTime());
13421346
obj.pushKV("mediantime", tip.GetMedianTimePast());

test/functional/rpc_blockchain.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def _test_getblockchaininfo(self):
133133

134134
keys = [
135135
'bestblockhash',
136+
'bits',
136137
'blocks',
137138
'chain',
138139
'chainwork',
@@ -142,6 +143,7 @@ def _test_getblockchaininfo(self):
142143
'mediantime',
143144
'pruned',
144145
'size_on_disk',
146+
'target',
145147
'time',
146148
'verificationprogress',
147149
'warnings',
@@ -198,6 +200,9 @@ def _test_getblockchaininfo(self):
198200
assert_equal(res['prune_target_size'], 576716800)
199201
assert_greater_than(res['size_on_disk'], 0)
200202

203+
assert_equal(res['bits'], nbits_str(REGTEST_N_BITS))
204+
assert_equal(res['target'], target_str(REGTEST_TARGET))
205+
201206
def check_signalling_deploymentinfo_result(self, gdi_result, height, blockhash, status_next):
202207
assert height >= 144 and height <= 287
203208

0 commit comments

Comments
 (0)