| 122 | } |
| 123 | |
| 124 | unsigned int DigishieldGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, |
| 125 | const Consensus::Params& params) |
| 126 | { |
| 127 | assert(pindexLast != nullptr); |
| 128 | unsigned int nProofOfWorkLimit = UintToArith256(params.PowLimit(true)).GetCompact(); // Always postfork. |
| 129 | |
| 130 | const CBlockIndex* pindexFirst = pindexLast; |
| 131 | arith_uint256 bnTot {0}; |
| 132 | for (int i = 0; pindexFirst && i < params.nDigishieldAveragingWindow; i++) { |
| 133 | arith_uint256 bnTmp; |
| 134 | bnTmp.SetCompact(pindexFirst->nBits); |
| 135 | bnTot += bnTmp; |
| 136 | pindexFirst = pindexFirst->pprev; |
| 137 | } |
| 138 | |
| 139 | if (pindexFirst == NULL) |
| 140 | return nProofOfWorkLimit; |
| 141 | |
| 142 | arith_uint256 bnAvg {bnTot / params.nDigishieldAveragingWindow}; |
| 143 | return DigishieldCalculateNextWorkRequired(bnAvg, pindexLast, pindexFirst, params); |
| 144 | } |
| 145 | |
| 146 | unsigned int DigishieldCalculateNextWorkRequired(arith_uint256 bnAvg, const CBlockIndex* pindexLast, const CBlockIndex* pindexFirst, const Consensus::Params& params) |
| 147 | { |
no test coverage detected