Exemplo n.º 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);
 }
Exemplo n.º 2
0
 /**
  * @param BlockIndex $prevIndex
  * @param $timeFirstBlock
  * @return int|string
  */
 public function calculateNextWorkRequired(BlockIndex $prevIndex, $timeFirstBlock)
 {
     $header = $prevIndex->getHeader();
     $math = $this->math;
     $timespan = $math->sub($header->getTimestamp(), $timeFirstBlock);
     $lowest = $math->div($this->params->powTargetTimespan(), 4);
     $highest = $math->mul($this->params->powTargetTimespan(), 4);
     if ($math->cmp($timespan, $lowest) < 0) {
         $timespan = $lowest;
     }
     if ($math->cmp($timespan, $highest) > 0) {
         $timespan = $highest;
     }
     $target = $math->compact()->set($header->getBits()->getInt());
     $limit = $this->math->compact()->set($this->params->powBitsLimit());
     $new = bcdiv(bcmul($target, $timespan), $this->params->powTargetTimespan());
     if ($math->cmp($new, $limit) > 0) {
         $new = $limit;
     }
     return $math->compact()->read($new, false);
 }
Exemplo n.º 3
0
 /**
  * @return int|string
  */
 public function getMaxTarget()
 {
     return $this->getTarget(Buffer::int($this->params->powBitsLimit(), 4, $this->math));
 }