Skip to content

Commit e7d9ffa

Browse files
laanwjcodablock
authored andcommitted
Merge bitcoin#7774: RPC: add versionHex in getblock and getblockheader JSON results
92107d5 RPC: add versionHex in getblock and getblockheader JSON results; expand data in getblockchaininfo bip9_softforks field. (mruddy)
1 parent 1cd653c commit e7d9ffa

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
@@ -106,6 +106,7 @@ def _test_getblockheader(self):
106106
assert isinstance(header['mediantime'], int)
107107
assert isinstance(header['nonce'], int)
108108
assert isinstance(header['version'], int)
109+
assert isinstance(int(header['versionHex'], 16), int)
109110
assert isinstance(header['difficulty'], Decimal)
110111

111112
if __name__ == '__main__':

src/rpc/blockchain.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
7575
result.push_back(Pair("confirmations", confirmations));
7676
result.push_back(Pair("height", blockindex->nHeight));
7777
result.push_back(Pair("version", blockindex->nVersion));
78+
result.push_back(Pair("versionHex", strprintf("%08x", blockindex->nVersion)));
7879
result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
7980
result.push_back(Pair("time", (int64_t)blockindex->nTime));
8081
result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
@@ -103,6 +104,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx
103104
result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
104105
result.push_back(Pair("height", blockindex->nHeight));
105106
result.push_back(Pair("version", block.nVersion));
107+
result.push_back(Pair("versionHex", strprintf("%08x", block.nVersion)));
106108
result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
107109
UniValue txs(UniValue::VARR);
108110
BOOST_FOREACH(const CTransaction&tx, block.vtx)
@@ -353,6 +355,7 @@ UniValue getblockheader(const UniValue& params, bool fHelp)
353355
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
354356
" \"height\" : n, (numeric) The block height or index\n"
355357
" \"version\" : n, (numeric) The block version\n"
358+
" \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n"
356359
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
357360
" \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
358361
" \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
@@ -501,6 +504,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
501504
" \"size\" : n, (numeric) The block size\n"
502505
" \"height\" : n, (numeric) The block height or index\n"
503506
" \"version\" : n, (numeric) The block version\n"
507+
" \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n"
504508
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
505509
" \"tx\" : [ (array of string) The transaction ids\n"
506510
" \"transactionid\" (string) The transaction id\n"
@@ -801,13 +805,20 @@ static UniValue BIP9SoftForkDesc(const std::string& name, const Consensus::Param
801805
{
802806
UniValue rv(UniValue::VOBJ);
803807
rv.push_back(Pair("id", name));
804-
switch (VersionBitsTipState(consensusParams, id)) {
808+
const ThresholdState thresholdState = VersionBitsTipState(consensusParams, id);
809+
switch (thresholdState) {
805810
case THRESHOLD_DEFINED: rv.push_back(Pair("status", "defined")); break;
806811
case THRESHOLD_STARTED: rv.push_back(Pair("status", "started")); break;
807812
case THRESHOLD_LOCKED_IN: rv.push_back(Pair("status", "locked_in")); break;
808813
case THRESHOLD_ACTIVE: rv.push_back(Pair("status", "active")); break;
809814
case THRESHOLD_FAILED: rv.push_back(Pair("status", "failed")); break;
810815
}
816+
if (THRESHOLD_STARTED == thresholdState)
817+
{
818+
rv.push_back(Pair("bit", consensusParams.vDeployments[id].bit));
819+
}
820+
rv.push_back(Pair("startTime", consensusParams.vDeployments[id].nStartTime));
821+
rv.push_back(Pair("timeout", consensusParams.vDeployments[id].nTimeout));
811822
return rv;
812823
}
813824

@@ -846,6 +857,9 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
846857
" {\n"
847858
" \"id\": \"xxxx\", (string) name of the softfork\n"
848859
" \"status\": \"xxxx\", (string) one of \"defined\", \"started\", \"lockedin\", \"active\", \"failed\"\n"
860+
" \"bit\": xx, (numeric) the bit, 0-28, in the block version field used to signal this soft fork\n"
861+
" \"startTime\": xx, (numeric) the minimum median time past of a block at which the bit gains its meaning\n"
862+
" \"timeout\": xx (numeric) the median time past of a block at which the deployment is considered failed if not yet locked in\n"
849863
" }\n"
850864
" ]\n"
851865
"}\n"

0 commit comments

Comments
 (0)