diff options
| author | jtimon <[email protected]> | 2014-07-05 12:05:33 +0200 |
|---|---|---|
| committer | jtimon <[email protected]> | 2014-08-23 13:21:51 +0200 |
| commit | b343c1a1e34f851e70649ad1f49855a7d878f9ef (patch) | |
| tree | b7c15e98c8a631420c186dd0acec51af4a02a061 /src/pow.cpp | |
| parent | Move UpdateTime to pow (diff) | |
| download | discoin-b343c1a1e34f851e70649ad1f49855a7d878f9ef.tar.xz discoin-b343c1a1e34f851e70649ad1f49855a7d878f9ef.zip | |
Move CBlockIndex::GetBlockWork() to pow::GetProofIncrement(nBits)
Diffstat (limited to 'src/pow.cpp')
| -rw-r--r-- | src/pow.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/pow.cpp b/src/pow.cpp index a99c582d7..d76928bda 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -127,3 +127,18 @@ void UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev) if (Params().AllowMinDifficultyBlocks()) pblock->nBits = GetNextWorkRequired(pindexPrev, pblock); } + +uint256 GetProofIncrement(unsigned int nBits) +{ + uint256 bnTarget; + bool fNegative; + bool fOverflow; + bnTarget.SetCompact(nBits, &fNegative, &fOverflow); + if (fNegative || fOverflow || bnTarget == 0) + return 0; + // 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; +} |