aboutsummaryrefslogtreecommitdiff
path: root/src/main.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-05-09 16:57:06 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-05-09 17:03:51 +0200
commit8bcfccbc2de25e3b40d1c222d7c5d9991345a0aa (patch)
treeec29908109f159efce4c7ccb6bba68125b1d04e8 /src/main.h
parent82564e21e79092a7e28aa5d31d8fdbdb3fd970ca (diff)
parent397668ea63e148a92f68e9fae578595585616770 (diff)
downloadbitcoin-8bcfccbc2de25e3b40d1c222d7c5d9991345a0aa.tar.xz
Merge pull request #4076
397668e Deduplicate uint* comparison operator logic (Pieter Wuille) df9eb5e Move {Get,Set}Compact from bignum to uint256 (Pieter Wuille) a703150 Add multiplication and division to uint160/uint256 (Pieter Wuille) 4d480c8 Exception instead of assigning 0 in case of wrong vector length (Pieter Wuille) eb2cbd7 Deduplicate shared code between uint160 and uint256 (Pieter Wuille)
Diffstat (limited to 'src/main.h')
-rw-r--r--src/main.h17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/main.h b/src/main.h
index 3d3773138d..f47c9ee825 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"
@@ -814,13 +813,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