mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-03 20:35:17 +02:00
Drop the chain argument to GetDifficulty
This removes the need to include rpc/blockchain.cpp in order to put GetDifficulty under test. GetDifficulty was called in two ways: * with a guaranteed non-null blockindex * with no argument Change the latter case to be provided chainActive.Tip() explicitly.
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
#include <rpc/blockchain.h>
|
||||
|
||||
#include <amount.h>
|
||||
#include <chain.h>
|
||||
#include <chainparams.h>
|
||||
#include <checkpoints.h>
|
||||
#include <coins.h>
|
||||
@@ -47,17 +46,13 @@ static std::mutex cs_blockchange;
|
||||
static std::condition_variable cond_blockchange;
|
||||
static CUpdatedBlock latestblock;
|
||||
|
||||
/* Calculate the difficulty for a given block index,
|
||||
* or the block index of the given chain.
|
||||
/* Calculate the difficulty for a given block index.
|
||||
*/
|
||||
double GetDifficulty(const CChain& chain, const CBlockIndex* blockindex)
|
||||
double GetDifficulty(const CBlockIndex* blockindex)
|
||||
{
|
||||
if (blockindex == nullptr)
|
||||
{
|
||||
if (chain.Tip() == nullptr)
|
||||
return 1.0;
|
||||
else
|
||||
blockindex = chain.Tip();
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
int nShift = (blockindex->nBits >> 24) & 0xff;
|
||||
@@ -78,11 +73,6 @@ double GetDifficulty(const CChain& chain, const CBlockIndex* blockindex)
|
||||
return dDiff;
|
||||
}
|
||||
|
||||
double GetDifficulty(const CBlockIndex* blockindex)
|
||||
{
|
||||
return GetDifficulty(chainActive, blockindex);
|
||||
}
|
||||
|
||||
UniValue blockheaderToJSON(const CBlockIndex* blockindex)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
@@ -352,7 +342,7 @@ static UniValue getdifficulty(const JSONRPCRequest& request)
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
return GetDifficulty();
|
||||
return GetDifficulty(chainActive.Tip());
|
||||
}
|
||||
|
||||
static std::string EntryDescriptionString()
|
||||
@@ -1229,7 +1219,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
|
||||
obj.pushKV("blocks", (int)chainActive.Height());
|
||||
obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1);
|
||||
obj.pushKV("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex());
|
||||
obj.pushKV("difficulty", (double)GetDifficulty());
|
||||
obj.pushKV("difficulty", (double)GetDifficulty(chainActive.Tip()));
|
||||
obj.pushKV("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast());
|
||||
obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), chainActive.Tip()));
|
||||
obj.pushKV("initialblockdownload", IsInitialBlockDownload());
|
||||
|
||||
Reference in New Issue
Block a user