From e580967a544b892b27af968ef54e0193f52197a0 Mon Sep 17 00:00:00 2001 From: myriadcoin Date: Fri, 26 Sep 2014 02:15:48 +0200 Subject: [PATCH] Fix GetDifficulty --- src/rpcblockchain.cpp | 11 ++++++----- src/rpcmisc.cpp | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 4d359770..92c55d2c 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -20,16 +20,17 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, Object& out, bool fIncludeH double GetDifficulty(const CBlockIndex* blockindex, int algo) { unsigned int nBits; - + // Floating point number that is a multiple of the minimum difficulty, // minimum difficulty = 1.0. if (blockindex == NULL) { - if (chainActive.Tip() == NULL) + CBlockIndex* tip = chainActive.Tip(); + if (tip == NULL) nBits = Params().ProofOfWorkLimit(ALGO_SHA256D).GetCompact(); else { - blockindex = GetLastBlockIndexForAlgo(chainActive.Tip(), algo); + blockindex = GetLastBlockIndexForAlgo(tip, algo); if (blockindex == NULL) nBits = Params().ProofOfWorkLimit(algo).GetCompact(); else @@ -38,11 +39,11 @@ double GetDifficulty(const CBlockIndex* blockindex, int algo) } else nBits = blockindex->nBits; - + int nShift = (nBits >> 24) & 0xff; double dDiff = - (double)0x0000ffff / (double)(blockindex->nBits & 0x00ffffff); + (double)0x0000ffff / (double)(nBits & 0x00ffffff); while (nShift < 29) { diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index e7add337..570fe1fc 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -81,6 +81,7 @@ Value getinfo(const Array& params, bool fHelp) obj.push_back(Pair("difficulty_skein", (double)GetDifficulty(NULL, ALGO_SKEIN))); obj.push_back(Pair("difficulty_qubit", (double)GetDifficulty(NULL, ALGO_QUBIT))); obj.push_back(Pair("testnet", TestNet())); + #ifdef ENABLE_WALLET if (pwalletMain) { obj.push_back(Pair("keypoololdest", pwalletMain->GetOldestKeyPoolTime())); @@ -92,6 +93,7 @@ Value getinfo(const Array& params, bool fHelp) #endif obj.push_back(Pair("relayfee", ValueFromAmount(CTransaction::nMinRelayTxFee))); obj.push_back(Pair("errors", GetWarnings("statusbar"))); + return obj; }