Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show All 38 Lines | |||||
static std::condition_variable cond_blockchange; | static std::condition_variable cond_blockchange; | ||||
static CUpdatedBlock latestblock; | static CUpdatedBlock latestblock; | ||||
extern void TxToJSON(const CTransaction &tx, const uint256 hashBlock, | extern void TxToJSON(const CTransaction &tx, const uint256 hashBlock, | ||||
UniValue &entry); | UniValue &entry); | ||||
void ScriptPubKeyToJSON(const CScript &scriptPubKey, UniValue &out, | void ScriptPubKeyToJSON(const CScript &scriptPubKey, UniValue &out, | ||||
bool fIncludeHex); | bool fIncludeHex); | ||||
double GetDifficulty(const CBlockIndex *blockindex) { | static double GetDifficultyFromBits(uint32_t nBits) { | ||||
// Floating point number that is a multiple of the minimum difficulty, | int nShift = (nBits >> 24) & 0xff; | ||||
// minimum difficulty = 1.0. | double dDiff = 0x0000ffff / double(nBits & 0x00ffffff); | ||||
if (blockindex == nullptr) { | |||||
if (chainActive.Tip() == nullptr) { | |||||
return 1.0; | |||||
} | |||||
blockindex = chainActive.Tip(); | |||||
} | |||||
int nShift = (blockindex->nBits >> 24) & 0xff; | |||||
double dDiff = double(0x0000ffff) / double(blockindex->nBits & 0x00ffffff); | |||||
while (nShift < 29) { | while (nShift < 29) { | ||||
dDiff *= 256.0; | dDiff *= 256.0; | ||||
nShift++; | nShift++; | ||||
} | } | ||||
while (nShift > 29) { | while (nShift > 29) { | ||||
dDiff /= 256.0; | dDiff /= 256.0; | ||||
nShift--; | nShift--; | ||||
} | } | ||||
return dDiff; | return dDiff; | ||||
} | } | ||||
double GetDifficulty(const CBlockIndex *blockindex) { | |||||
// Floating point number that is a multiple of the minimum difficulty, | |||||
// minimum difficulty = 1.0. | |||||
if (blockindex == nullptr) { | |||||
return 1.0; | |||||
} | |||||
return GetDifficultyFromBits(blockindex->nBits); | |||||
} | |||||
UniValue blockheaderToJSON(const CBlockIndex *blockindex) { | UniValue blockheaderToJSON(const CBlockIndex *blockindex) { | ||||
UniValue result(UniValue::VOBJ); | UniValue result(UniValue::VOBJ); | ||||
result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex())); | result.push_back(Pair("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; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | if (request.fHelp || request.params.size() != 0) { | ||||
"difficulty as a multiple of the minimum " | "difficulty as a multiple of the minimum " | ||||
"difficulty.\n" | "difficulty.\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getdifficulty", "") + | HelpExampleCli("getdifficulty", "") + | ||||
HelpExampleRpc("getdifficulty", "")); | HelpExampleRpc("getdifficulty", "")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return GetDifficulty(); | return GetDifficulty(chainActive.Tip()); | ||||
} | } | ||||
std::string EntryDescriptionString() { | std::string EntryDescriptionString() { | ||||
return " \"size\" : n, (numeric) transaction size.\n" | return " \"size\" : n, (numeric) transaction size.\n" | ||||
" \"fee\" : n, (numeric) transaction fee in " + | " \"fee\" : n, (numeric) transaction fee in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"modifiedfee\" : n, (numeric) transaction fee with fee " | " \"modifiedfee\" : n, (numeric) transaction fee with fee " | ||||
▲ Show 20 Lines • Show All 924 Lines • ▼ Show 20 Lines | UniValue getblockchaininfo(const Config &config, | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.push_back(Pair("chain", Params().NetworkIDString())); | obj.push_back(Pair("chain", Params().NetworkIDString())); | ||||
obj.push_back(Pair("blocks", int(chainActive.Height()))); | obj.push_back(Pair("blocks", int(chainActive.Height()))); | ||||
obj.push_back( | obj.push_back( | ||||
Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1)); | Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1)); | ||||
obj.push_back( | obj.push_back( | ||||
Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); | Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); | ||||
obj.push_back(Pair("difficulty", double(GetDifficulty()))); | obj.push_back(Pair("difficulty", double(GetDifficulty(chainActive.Tip())))); | ||||
obj.push_back( | obj.push_back( | ||||
Pair("mediantime", int64_t(chainActive.Tip()->GetMedianTimePast()))); | Pair("mediantime", int64_t(chainActive.Tip()->GetMedianTimePast()))); | ||||
obj.push_back( | obj.push_back( | ||||
Pair("verificationprogress", | Pair("verificationprogress", | ||||
GuessVerificationProgress(Params().TxData(), chainActive.Tip()))); | GuessVerificationProgress(Params().TxData(), chainActive.Tip()))); | ||||
obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); | obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); | ||||
obj.push_back(Pair("pruned", fPruneMode)); | obj.push_back(Pair("pruned", fPruneMode)); | ||||
▲ Show 20 Lines • Show All 349 Lines • Show Last 20 Lines |