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

Function blockheaderToJSON

src/rpc/blockchain.cpp:97–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95}
96
97UniValue blockheaderToJSON(const CBlockIndex* blockindex)
98{
99 AssertLockHeld(cs_main);
100 UniValue result(UniValue::VOBJ);
101 result.pushKV("hash", blockindex->GetBlockHash().GetHex());
102 int confirmations = -1;
103 // Only report confirmations if the block is on the main chain
104 if (chainActive.Contains(blockindex))
105 confirmations = chainActive.Height() - blockindex->nHeight + 1;
106 result.pushKV("confirmations", confirmations);
107 result.pushKV("height", blockindex->nHeight);
108 result.pushKV("version", blockindex->nVersion);
109 result.pushKV("versionHex", strprintf("%08x", blockindex->nVersion));
110 result.pushKV("merkleroot", blockindex->hashMerkleRoot.GetHex());
111 result.pushKV("time", (int64_t)blockindex->nTime);
112 result.pushKV("mediantime", (int64_t)blockindex->GetMedianTimePast());
113 result.pushKV("nonceUint32", (uint64_t)((uint32_t)blockindex->nNonce.GetUint64(0)));
114 result.pushKV("nonce", blockindex->nNonce.GetHex());
115 result.pushKV("solution", HexStr(blockindex->nSolution));
116 result.pushKV("bits", strprintf("%08x", blockindex->nBits));
117 result.pushKV("difficulty", GetDifficulty(blockindex));
118 result.pushKV("chainwork", blockindex->nChainWork.GetHex());
119 result.pushKV("nTx", (uint64_t)blockindex->nTx);
120 result.pushKV("receivedTime", (uint64_t)blockindex->GetHeaderReceivedTime());
121
122 if (blockindex->pprev)
123 result.pushKV("previousblockhash", blockindex->pprev->GetBlockHash().GetHex());
124 CBlockIndex *pnext = chainActive.Next(blockindex);
125 if (pnext)
126 result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex());
127 return result;
128}
129
130UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails)
131{

Callers 2

rest_headersFunction · 0.85
getblockheaderFunction · 0.85

Calls 11

HexStrFunction · 0.85
GetDifficultyFunction · 0.85
HeightMethod · 0.80
GetMedianTimePastMethod · 0.80
GetUint64Method · 0.80
GetHeaderReceivedTimeMethod · 0.80
pushKVMethod · 0.45
GetHexMethod · 0.45
GetBlockHashMethod · 0.45
ContainsMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected