| 144 | } |
| 145 | |
| 146 | unsigned int DigishieldCalculateNextWorkRequired(arith_uint256 bnAvg, const CBlockIndex* pindexLast, const CBlockIndex* pindexFirst, const Consensus::Params& params) |
| 147 | { |
| 148 | if (params.fPowNoRetargeting) |
| 149 | return pindexLast->nBits; |
| 150 | |
| 151 | int64_t nLastBlockTime = pindexLast->GetMedianTimePast(); |
| 152 | int64_t nFirstBlockTime = pindexFirst->GetMedianTimePast(); |
| 153 | // Limit adjustment |
| 154 | int64_t nActualTimespan = nLastBlockTime - nFirstBlockTime; |
| 155 | |
| 156 | if (nActualTimespan < params.DigishieldMinActualTimespan()) |
| 157 | nActualTimespan = params.DigishieldMinActualTimespan(); |
| 158 | if (nActualTimespan > params.DigishieldMaxActualTimespan()) |
| 159 | nActualTimespan = params.DigishieldMaxActualTimespan(); |
| 160 | |
| 161 | // Retarget |
| 162 | const arith_uint256 bnPowLimit = UintToArith256(params.PowLimit(true)); |
| 163 | arith_uint256 bnNew {bnAvg}; |
| 164 | bnNew /= params.DigishieldAveragingWindowTimespan(); |
| 165 | bnNew *= nActualTimespan; |
| 166 | |
| 167 | if (bnNew > bnPowLimit) |
| 168 | bnNew = bnPowLimit; |
| 169 | |
| 170 | return bnNew.GetCompact(); |
| 171 | } |
| 172 | |
| 173 | unsigned int BitcoinGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) |
| 174 | { |
no test coverage detected