Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | static int ComputeNextBlockAndDepth(const CBlockIndex *tip, | ||||
next = nullptr; | next = nullptr; | ||||
return blockindex == tip ? 1 : -1; | return blockindex == tip ? 1 : -1; | ||||
} | } | ||||
UniValue blockheaderToJSON(const CBlockIndex *tip, | UniValue blockheaderToJSON(const CBlockIndex *tip, | ||||
const CBlockIndex *blockindex) { | const CBlockIndex *blockindex) { | ||||
// Serialize passed information without accessing chain state of the active | // Serialize passed information without accessing chain state of the active | ||||
// chain! | // chain! | ||||
// For performance reasons | |||||
AssertLockNotHeld(cs_main); | |||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.pushKV("hash", blockindex->GetBlockHash().GetHex()); | result.pushKV("hash", blockindex->GetBlockHash().GetHex()); | ||||
const CBlockIndex *pnext; | const CBlockIndex *pnext; | ||||
int confirmations = ComputeNextBlockAndDepth(tip, blockindex, pnext); | int confirmations = ComputeNextBlockAndDepth(tip, blockindex, pnext); | ||||
result.pushKV("confirmations", confirmations); | result.pushKV("confirmations", confirmations); | ||||
result.pushKV("height", blockindex->nHeight); | result.pushKV("height", blockindex->nHeight); | ||||
result.pushKV("version", blockindex->nVersion); | result.pushKV("version", blockindex->nVersion); | ||||
result.pushKV("versionHex", strprintf("%08x", blockindex->nVersion)); | result.pushKV("versionHex", strprintf("%08x", blockindex->nVersion)); | ||||
Show All 15 Lines | UniValue blockheaderToJSON(const CBlockIndex *tip, | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
UniValue blockToJSON(const CBlock &block, const CBlockIndex *tip, | UniValue blockToJSON(const CBlock &block, const CBlockIndex *tip, | ||||
const CBlockIndex *blockindex, bool txDetails) { | const CBlockIndex *blockindex, bool txDetails) { | ||||
// Serialize passed information without accessing chain state of the active | // Serialize passed information without accessing chain state of the active | ||||
// chain! | // chain! | ||||
// For performance reasons | |||||
AssertLockNotHeld(cs_main); | |||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.pushKV("hash", blockindex->GetBlockHash().GetHex()); | result.pushKV("hash", blockindex->GetBlockHash().GetHex()); | ||||
const CBlockIndex *pnext; | const CBlockIndex *pnext; | ||||
int confirmations = ComputeNextBlockAndDepth(tip, blockindex, pnext); | int confirmations = ComputeNextBlockAndDepth(tip, blockindex, pnext); | ||||
result.pushKV("confirmations", confirmations); | result.pushKV("confirmations", confirmations); | ||||
result.pushKV("size", (int)::GetSerializeSize(block, PROTOCOL_VERSION)); | result.pushKV("size", (int)::GetSerializeSize(block, PROTOCOL_VERSION)); | ||||
result.pushKV("height", blockindex->nHeight); | result.pushKV("height", blockindex->nHeight); | ||||
result.pushKV("version", block.nVersion); | result.pushKV("version", block.nVersion); | ||||
▲ Show 20 Lines • Show All 2,601 Lines • Show Last 20 Lines |