diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-04-20 03:19:20 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2014-05-09 16:44:59 +0200 |
commit | df9eb5e14fa8072bc8a82b59e712c2ba36f13f4c (patch) | |
tree | 64c961273c28988b9be4138490e6db570a3b66d0 /src/main.h | |
parent | a7031507e647da0723bf289dadba10ef1a50f278 (diff) |
Move {Get,Set}Compact from bignum to uint256
Diffstat (limited to 'src/main.h')
-rw-r--r-- | src/main.h | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/main.h b/src/main.h index c69e0d2a3c..796a3031c9 100644 --- a/src/main.h +++ b/src/main.h @@ -10,7 +10,6 @@ #include "bitcoin-config.h" #endif -#include "bignum.h" #include "chainparams.h" #include "coins.h" #include "core.h" @@ -816,13 +815,19 @@ public: return (int64_t)nTime; } - CBigNum GetBlockWork() const + uint256 GetBlockWork() const { - CBigNum bnTarget; - bnTarget.SetCompact(nBits); - if (bnTarget <= 0) + uint256 bnTarget; + bool fNegative; + bool fOverflow; + bnTarget.SetCompact(nBits, &fNegative, &fOverflow); + if (fNegative || fOverflow || bnTarget == 0) return 0; - return (CBigNum(1)<<256) / (bnTarget+1); + // We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256 + // as it's too large for a uint256. However, as 2**256 is at least as large + // as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / (bnTarget+1)) + 1, + // or ~bnTarget / (nTarget+1) + 1. + return (~bnTarget / (bnTarget + 1)) + 1; } bool CheckIndex() const |