diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-05 19:15:15 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2011-06-05 20:25:56 +0200 |
commit | 822f2e3ddfcc98a7633f71665fa9d7879bc63115 (patch) | |
tree | a6970cc8867ecac9e7bd420732cbc4be5e7af052 /core/src/rpc.cpp | |
parent | b7726d924ef7082b1f1d532ba6f840bc7b267b47 (diff) | |
download | bitcoin-822f2e3ddfcc98a7633f71665fa9d7879bc63115.tar.xz |
update to newest git bitcoin core
Diffstat (limited to 'core/src/rpc.cpp')
-rw-r--r-- | core/src/rpc.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/core/src/rpc.cpp b/core/src/rpc.cpp index 9efcbbb15a..530bef4a43 100644 --- a/core/src/rpc.cpp +++ b/core/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) |