MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / blockheaderToJSON

Function blockheaderToJSON

src/rpcblockchain.cpp:54–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52}
53
54UniValue blockheaderToJSON(const CBlockIndex* blockindex)
55{
56 UniValue result(UniValue::VOBJ);
57 result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex()));
58 int confirmations = -1;
59 // Only report confirmations if the block is on the main chain
60 if (chainActive.Contains(blockindex))
61 confirmations = chainActive.Height() - blockindex->nHeight + 1;
62 result.push_back(Pair("confirmations", confirmations));
63 result.push_back(Pair("height", blockindex->nHeight));
64 result.push_back(Pair("version", blockindex->nVersion));
65 result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
66 result.push_back(Pair("time", (int64_t)blockindex->nTime));
67 result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
68 result.push_back(Pair("nonce", (uint64_t)blockindex->nNonce));
69 result.push_back(Pair("bits", strprintf("%08x", blockindex->nBits)));
70 result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
71 result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
72 result.push_back(Pair("sizelimit", blockindex->nMaxBlockSize));
73 result.push_back(Pair("sizelimitvote", blockindex->nMaxBlockSizeVote));
74
75 if (blockindex->pprev)
76 result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
77 CBlockIndex *pnext = chainActive.Next(blockindex);
78 if (pnext)
79 result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex()));
80 return result;
81}
82
83UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
84{

Callers 2

getblockheaderFunction · 0.85
BOOST_FOREACHFunction · 0.85

Calls 9

PairFunction · 0.85
GetDifficultyFunction · 0.85
HeightMethod · 0.80
GetMedianTimePastMethod · 0.80
push_backMethod · 0.45
GetHexMethod · 0.45
GetBlockHashMethod · 0.45
ContainsMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected