Beispiel #1
0
 /**
  * @param BlockIndexInterface $prevIndex
  * @param int $timeFirstBlock
  * @return int
  */
 public function calculateNextWorkRequired(BlockIndexInterface $prevIndex, $timeFirstBlock)
 {
     $header = $prevIndex->getHeader();
     $math = $this->math;
     $timespan = $this->calculateWorkTimespan($timeFirstBlock, $header);
     $negative = false;
     $overflow = false;
     $target = $math->decodeCompact($header->getBits(), $negative, $overflow);
     $limit = $this->math->decodeCompact($this->params->powBitsLimit(), $negative, $overflow);
     $new = gmp_init(bcdiv(bcmul($target, $timespan), $this->params->powTargetTimespan()), 10);
     if ($math->cmp($new, $limit) > 0) {
         $new = $limit;
     }
     return gmp_strval($math->encodeCompact($new, false), 10);
 }