Skip to content

Commit baa504f

Browse files
committed
rpc: add target to getmininginfo result
1 parent 2a7bfeb commit baa504f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/rpc/mining.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ static RPCHelpMan getmininginfo()
423423
{RPCResult::Type::NUM, "currentblocktx", /*optional=*/true, "The number of block transactions of the last assembled block (only present if a block was ever assembled)"},
424424
{RPCResult::Type::STR_HEX, "bits", "The current nBits, compact representation of the block difficulty target"},
425425
{RPCResult::Type::NUM, "difficulty", "The current difficulty"},
426+
{RPCResult::Type::STR_HEX, "target", "The current target"},
426427
{RPCResult::Type::NUM, "networkhashps", "The network hashes per second"},
427428
{RPCResult::Type::NUM, "pooledtx", "The size of the mempool"},
428429
{RPCResult::Type::STR, "chain", "current network name (" LIST_CHAIN_NAMES ")"},
@@ -455,6 +456,7 @@ static RPCHelpMan getmininginfo()
455456
if (BlockAssembler::m_last_block_num_txs) obj.pushKV("currentblocktx", *BlockAssembler::m_last_block_num_txs);
456457
obj.pushKV("bits", strprintf("%08x", tip.nBits));
457458
obj.pushKV("difficulty", GetDifficulty(tip));
459+
obj.pushKV("target", GetTarget(tip, chainman.GetConsensus().powLimit).GetHex());
458460
obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request));
459461
obj.pushKV("pooledtx", (uint64_t)mempool.size());
460462
obj.pushKV("chain", chainman.GetParams().GetChainTypeString());

test/functional/mining_basic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
NORMAL_GBT_REQUEST_PARAMS,
1818
TIME_GENESIS_BLOCK,
1919
REGTEST_N_BITS,
20+
REGTEST_TARGET,
2021
nbits_str,
22+
target_str,
2123
)
2224
from test_framework.messages import (
2325
BLOCK_HEADER_SIZE,
@@ -209,6 +211,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
209211
assert 'currentblocktx' not in mining_info
210212
assert 'currentblockweight' not in mining_info
211213
assert_equal(mining_info['bits'], nbits_str(REGTEST_N_BITS))
214+
assert_equal(mining_info['target'], target_str(REGTEST_TARGET))
212215
assert_equal(mining_info['difficulty'], Decimal('4.656542373906925E-10'))
213216
assert_equal(mining_info['networkhashps'], Decimal('0.003333333333333334'))
214217
assert_equal(mining_info['pooledtx'], 0)

0 commit comments

Comments
 (0)