Beispiel #1
0
 /**
  * @param Buffer $bits
  * @return string
  */
 public function getDifficulty(Buffer $bits)
 {
     $target = $this->getTarget($bits);
     $lowest = $this->getMaxTarget();
     $lowest = $this->math->mul($lowest, $this->math->pow(10, self::DIFF_PRECISION));
     $difficulty = str_pad($this->math->div($lowest, $target), self::DIFF_PRECISION + 1, '0', STR_PAD_LEFT);
     $intPart = substr($difficulty, 0, 0 - self::DIFF_PRECISION);
     $decPart = substr($difficulty, 0 - self::DIFF_PRECISION, self::DIFF_PRECISION);
     return $intPart . '.' . $decPart;
 }
Beispiel #2
0
 /**
  * @param BufferInterface $buffer
  * @return int
  */
 private function parseBuffer(BufferInterface $buffer)
 {
     $size = $buffer->getSize();
     if ($size === 0) {
         return '0';
     }
     $chars = array_map(function ($binary) {
         return ord($binary);
     }, str_split($buffer->getBinary(), 1));
     $result = 0;
     for ($i = 0; $i < $size; $i++) {
         $mul = $this->math->mul($i, 8);
         $byte = $this->math->leftShift($chars[$i], $mul);
         $result = $this->math->bitwiseOr($result, $byte);
     }
     if ($chars[count($chars) - 1] & 0x80) {
         $mask = gmp_strval(gmp_com($this->math->leftShift(0x80, 8 * ($size - 1))), 10);
         return $this->math->sub(0, $this->math->bitwiseAnd($result, $mask));
     }
     return $result;
 }
Beispiel #3
0
 /**
  * @param int|string $amount
  * @return bool
  */
 public function checkAmount($amount)
 {
     return $this->math->cmp($amount, $this->math->mul($this->params->maxMoney(), Amount::COIN)) < 0;
 }