Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | double GetDifficulty(const CBlockIndex *blockindex) { | ||||
if (blockindex == nullptr) { | if (blockindex == nullptr) { | ||||
return 1.0; | return 1.0; | ||||
} | } | ||||
return GetDifficultyFromBits(blockindex->nBits); | return GetDifficultyFromBits(blockindex->nBits); | ||||
} | } | ||||
UniValue blockheaderToJSON(const CBlockIndex *blockindex) { | UniValue blockheaderToJSON(const CBlockIndex *blockindex) { | ||||
AssertLockHeld(cs_main); | |||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.pushKV("hash", blockindex->GetBlockHash().GetHex()); | result.pushKV("hash", blockindex->GetBlockHash().GetHex()); | ||||
int confirmations = -1; | int confirmations = -1; | ||||
// Only report confirmations if the block is on the main chain | // Only report confirmations if the block is on the main chain | ||||
if (chainActive.Contains(blockindex)) { | if (chainActive.Contains(blockindex)) { | ||||
confirmations = chainActive.Height() - blockindex->nHeight + 1; | confirmations = chainActive.Height() - blockindex->nHeight + 1; | ||||
} | } | ||||
result.pushKV("confirmations", confirmations); | result.pushKV("confirmations", confirmations); | ||||
Show All 16 Lines | UniValue blockheaderToJSON(const CBlockIndex *blockindex) { | ||||
if (pnext) { | if (pnext) { | ||||
result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); | result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
UniValue blockToJSON(const Config &config, const CBlock &block, | UniValue blockToJSON(const Config &config, const CBlock &block, | ||||
const CBlockIndex *blockindex, bool txDetails) { | const CBlockIndex *blockindex, bool txDetails) { | ||||
AssertLockHeld(cs_main); | |||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.pushKV("hash", blockindex->GetBlockHash().GetHex()); | result.pushKV("hash", blockindex->GetBlockHash().GetHex()); | ||||
int confirmations = -1; | int confirmations = -1; | ||||
// Only report confirmations if the block is on the main chain | // Only report confirmations if the block is on the main chain | ||||
if (chainActive.Contains(blockindex)) { | if (chainActive.Contains(blockindex)) { | ||||
confirmations = chainActive.Height() - blockindex->nHeight + 1; | confirmations = chainActive.Height() - blockindex->nHeight + 1; | ||||
} | } | ||||
result.pushKV("confirmations", confirmations); | result.pushKV("confirmations", confirmations); | ||||
▲ Show 20 Lines • Show All 1,746 Lines • Show Last 20 Lines |