aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rpc.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/rpc.cpp b/src/rpc.cpp
index 9efcbbb15a..530bef4a43 100644
--- a/src/rpc.cpp
+++ b/src/rpc.cpp
@@ -199,12 +199,26 @@ double GetDifficulty()
{
// Floating point number that is a multiple of the minimum difficulty,
// minimum difficulty = 1.0.
+
if (pindexBest == NULL)
return 1.0;
- int nShift = 256 - 32 - 31; // to fit in a uint
- double dMinimum = (CBigNum().SetCompact(bnProofOfWorkLimit.GetCompact()) >> nShift).getuint();
- double dCurrently = (CBigNum().SetCompact(pindexBest->nBits) >> nShift).getuint();
- return dMinimum / dCurrently;
+ int nShift = (pindexBest->nBits >> 24) & 0xff;
+
+ double dDiff =
+ (double)0x0000ffff / (double)(pindexBest->nBits & 0x00ffffff);
+
+ while (nShift < 29)
+ {
+ dDiff *= 256.0;
+ nShift++;
+ }
+ while (nShift > 29)
+ {
+ dDiff /= 256.0;
+ nShift--;
+ }
+
+ return dDiff;
}
Value getdifficulty(const Array& params, bool fHelp)