Skip to content

Commit 92107d5

Browse files
committed
RPC: add versionHex in getblock and getblockheader JSON results; expand data in getblockchaininfo bip9_softforks field.
1 parent a914968 commit 92107d5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

qa/rpc-tests/blockchain.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def _test_getblockheader(self):
8282
assert isinstance(header['mediantime'], int)
8383
assert isinstance(header['nonce'], int)
8484
assert isinstance(header['version'], int)
85+
assert isinstance(int(header['versionHex'], 16), int)
8586
assert isinstance(header['difficulty'], Decimal)
8687

8788
if __name__ == '__main__':

src/rpc/blockchain.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
7070
result.push_back(Pair("confirmations", confirmations));
7171
result.push_back(Pair("height", blockindex->nHeight));
7272
result.push_back(Pair("version", blockindex->nVersion));
73+
result.push_back(Pair("versionHex", strprintf("%08x", blockindex->nVersion)));
7374
result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
7475
result.push_back(Pair("time", (int64_t)blockindex->nTime));
7576
result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
@@ -98,6 +99,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
9899
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
99100
result.push_back(Pair("height", blockindex->nHeight));
100101
result.push_back(Pair("version", block.nVersion));
102+
result.push_back(Pair("versionHex", strprintf("%08x", block.nVersion)));
101103
result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
102104
UniValue txs(UniValue::VARR);
103105
BOOST_FOREACH(const CTransaction&tx, block.vtx)
@@ -316,6 +318,7 @@ UniValue getblockheader(const UniValue& params, bool fHelp)
316318
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
317319
" \"height\" : n, (numeric) The block height or index\n"
318320
" \"version\" : n, (numeric) The block version\n"
321+
" \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n"
319322
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
320323
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
321324
" \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
@@ -375,6 +378,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
375378
" \"size\" : n, (numeric) The block size\n"
376379
" \"height\" : n, (numeric) The block height or index\n"
377380
" \"version\" : n, (numeric) The block version\n"
381+
" \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n"
378382
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
379383
" \"tx\" : [ (array of string) The transaction ids\n"
380384
" \"transactionid\" (string) The transaction id\n"
@@ -608,13 +612,20 @@ static UniValue BIP9SoftForkDesc(const std::string& name, const Consensus::Param
608612
{
609613
UniValue rv(UniValue::VOBJ);
610614
rv.push_back(Pair("id", name));
611-
switch (VersionBitsTipState(consensusParams, id)) {
615+
const ThresholdState thresholdState = VersionBitsTipState(consensusParams, id);
616+
switch (thresholdState) {
612617
case THRESHOLD_DEFINED: rv.push_back(Pair("status", "defined")); break;
613618
case THRESHOLD_STARTED: rv.push_back(Pair("status", "started")); break;
614619
case THRESHOLD_LOCKED_IN: rv.push_back(Pair("status", "locked_in")); break;
615620
case THRESHOLD_ACTIVE: rv.push_back(Pair("status", "active")); break;
616621
case THRESHOLD_FAILED: rv.push_back(Pair("status", "failed")); break;
617622
}
623+
if (THRESHOLD_STARTED == thresholdState)
624+
{
625+
rv.push_back(Pair("bit", consensusParams.vDeployments[id].bit));
626+
}
627+
rv.push_back(Pair("startTime", consensusParams.vDeployments[id].nStartTime));
628+
rv.push_back(Pair("timeout", consensusParams.vDeployments[id].nTimeout));
618629
return rv;
619630
}
620631

@@ -653,6 +664,9 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
653664
" {\n"
654665
" \"id\": \"xxxx\", (string) name of the softfork\n"
655666
" \"status\": \"xxxx\", (string) one of \"defined\", \"started\", \"lockedin\", \"active\", \"failed\"\n"
667+
" \"bit\": xx, (numeric) the bit, 0-28, in the block version field used to signal this soft fork\n"
668+
" \"startTime\": xx, (numeric) the minimum median time past of a block at which the bit gains its meaning\n"
669+
" \"timeout\": xx (numeric) the median time past of a block at which the deployment is considered failed if not yet locked in\n"
656670
" }\n"
657671
" ]\n"
658672
"}\n"

0 commit comments

Comments
 (0)