MCPcopy Create free account
hub / github.com/ElementsProject/elements / blockheaderToJSON

Function blockheaderToJSON

src/rpc/blockchain.cpp:196–253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex_)
197{
198 // Serialize passed information without accessing chain state of the active chain!
199 AssertLockNotHeld(cs_main); // For performance reasons
200
201 CBlockIndex tmpBlockIndexFull;
202 const CBlockIndex* blockindex;
203 {
204 LOCK(cs_main);
205 blockindex = blockindex_->untrim_to(&tmpBlockIndexFull);
206 }
207
208 UniValue result(UniValue::VOBJ);
209 result.pushKV("hash", blockindex->GetBlockHash().GetHex());
210 const CBlockIndex* pnext;
211 int confirmations = ComputeNextBlockAndDepth(tip, blockindex_, pnext);
212 result.pushKV("confirmations", confirmations);
213 result.pushKV("height", blockindex->nHeight);
214 result.pushKV("version", blockindex->nVersion);
215 result.pushKV("versionHex", strprintf("%08x", blockindex->nVersion));
216 result.pushKV("merkleroot", blockindex->hashMerkleRoot.GetHex());
217 result.pushKV("time", (int64_t)blockindex->nTime);
218 result.pushKV("mediantime", (int64_t)blockindex->GetMedianTimePast());
219 if (!g_signed_blocks) {
220 result.pushKV("nonce", (uint64_t)blockindex->nNonce);
221 result.pushKV("bits", strprintf("%08x", blockindex->nBits));
222 result.pushKV("difficulty", GetDifficulty(blockindex));
223 result.pushKV("chainwork", blockindex->nChainWork.GetHex());
224 } else {
225 if (!blockindex->is_dynafed_block()) {
226 if (blockindex->trimmed()) {
227 result.pushKV("signblock_witness_asm", "<trimmed>");
228 result.pushKV("signblock_witness_hex", "<trimmed>");
229 result.pushKV("signblock_challenge", "<trimmed>");
230 result.pushKV("warning", "Fields missing due to -trim_headers flag.");
231 } else {
232 result.pushKV("signblock_witness_asm", ScriptToAsmStr(blockindex->get_proof().solution));
233 result.pushKV("signblock_witness_hex", HexStr(blockindex->get_proof().solution));
234 result.pushKV("signblock_challenge", HexStr(blockindex->get_proof().challenge));
235 }
236 } else {
237 if (blockindex->trimmed()) {
238 result.pushKV("signblock_witness_hex", "<trimmed>");
239 result.pushKV("dynamic_parameters", "<trimmed>");
240 result.pushKV("warning", "Fields missing due to -trim_headers flag.");
241 } else {
242 result.pushKV("signblock_witness_hex", EncodeHexScriptWitness(blockindex->signblock_witness()));
243 result.pushKV("dynamic_parameters", dynaParamsToJSON(blockindex->dynafed_params()));
244 }
245 }
246 }
247 result.pushKV("nTx", (uint64_t)blockindex->nTx);
248 if (blockindex_->pprev)
249 result.pushKV("previousblockhash", blockindex->pprev->GetBlockHash().GetHex());
250 if (pnext)
251 result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex());
252 return result;
253}

Callers 3

rest_headersFunction · 0.85
blockToJSONFunction · 0.85
getblockheaderFunction · 0.85

Calls 12

ComputeNextBlockAndDepthFunction · 0.85
GetDifficultyFunction · 0.85
ScriptToAsmStrFunction · 0.85
EncodeHexScriptWitnessFunction · 0.85
dynaParamsToJSONFunction · 0.85
GetMedianTimePastMethod · 0.80
is_dynafed_blockMethod · 0.80
trimmedMethod · 0.80
HexStrFunction · 0.50
pushKVMethod · 0.45
GetHexMethod · 0.45
GetBlockHashMethod · 0.45

Tested by

no test coverage detected