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

Function blockheaderToJSON

src/rpc/blockchain.cpp:164–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162}
163
164UniValue blockheaderToJSON(const CBlockIndex& tip, const CBlockIndex& blockindex, const uint256 pow_limit)
165{
166 // Serialize passed information without accessing chain state of the active chain!
167 AssertLockNotHeld(cs_main); // For performance reasons
168
169 UniValue result(UniValue::VOBJ);
170 result.pushKV("hash", blockindex.GetBlockHash().GetHex());
171 const CBlockIndex* pnext;
172 int confirmations = ComputeNextBlockAndDepth(tip, blockindex, pnext);
173 result.pushKV("confirmations", confirmations);
174 result.pushKV("height", blockindex.nHeight);
175 result.pushKV("version", blockindex.nVersion);
176 result.pushKV("versionHex", strprintf("%08x", blockindex.nVersion));
177 result.pushKV("merkleroot", blockindex.hashMerkleRoot.GetHex());
178 result.pushKV("time", blockindex.nTime);
179 result.pushKV("mediantime", blockindex.GetMedianTimePast());
180 result.pushKV("nonce", blockindex.nNonce);
181 result.pushKV("bits", strprintf("%08x", blockindex.nBits));
182 result.pushKV("target", GetTarget(blockindex, pow_limit).GetHex());
183 result.pushKV("difficulty", GetDifficulty(blockindex));
184 result.pushKV("chainwork", blockindex.nChainWork.GetHex());
185 result.pushKV("nTx", blockindex.nTx);
186
187 if (blockindex.pprev)
188 result.pushKV("previousblockhash", blockindex.pprev->GetBlockHash().GetHex());
189 if (pnext)
190 result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex());
191 return result;
192}
193
194/** Serialize coinbase transaction metadata */
195UniValue coinbaseTxToJSON(const CTransaction& coinbase_tx)

Callers 3

rest_headersFunction · 0.85
blockToJSONFunction · 0.85
getblockheaderFunction · 0.85

Calls 7

ComputeNextBlockAndDepthFunction · 0.85
GetTargetFunction · 0.85
GetDifficultyFunction · 0.85
pushKVMethod · 0.80
GetMedianTimePastMethod · 0.80
GetHexMethod · 0.45
GetBlockHashMethod · 0.45

Tested by

no test coverage detected