From 24809b16b63c43ca3b2935889b32605b76c2f2ea Mon Sep 17 00:00:00 2001 From: aniemerg Date: Mon, 20 Jun 2016 22:21:42 -0400 Subject: [PATCH] Update GetDifficulty() to use consensus.powLimit from consensus parameters. Fixes #1032. --- src/rpcblockchain.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 4d46a1370..0450a5a3b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -34,16 +34,20 @@ double GetDifficulty(const CBlockIndex* blockindex) } int nShift = (blockindex->nBits >> 24) & 0xff; + uint32_t powLimit = + UintToArith256(Params().GetConsensus().powLimit).GetCompact();; + int nShiftAmount = (powLimit >> 24) & 0xff; double dDiff = - (double)0x0000ffff / (double)(blockindex->nBits & 0x00ffffff); + (double)(powLimit & 0x00ffffff) / + (double)(blockindex->nBits & 0x00ffffff); - while (nShift < 29) + while (nShift < nShiftAmount) { dDiff *= 256.0; nShift++; } - while (nShift > 29) + while (nShift > nShiftAmount) { dDiff /= 256.0; nShift--;