aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/blockchain.cpp
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2018-05-20 14:04:15 -0700
committerBen Woosley <ben.woosley@gmail.com>2018-05-20 22:19:42 -0700
commitebec7317ca1acbc65afa7fb08fc219c315fc4527 (patch)
tree7cce4ca196629a3bf18637f2adfee7fc7bfc717b /src/rpc/blockchain.cpp
parentd792e47421fcb9ce3b381c1e6d8902777ae3f9f3 (diff)
downloadbitcoin-ebec7317ca1acbc65afa7fb08fc219c315fc4527.tar.xz
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.
Diffstat (limited to 'src/rpc/blockchain.cpp')
-rw-r--r--src/rpc/blockchain.cpp20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index 238d8c9d95..5cfc14e89d 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -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());