Example #1
0
 /**
  * @param BufferInterface $vch
  * @param bool $fRequireMinimal
  * @param int $maxNumSize
  * @param Math|null $math
  * @return self
  */
 public static function buffer(BufferInterface $vch, $fRequireMinimal, $maxNumSize = self::MAX_NUM_SIZE, Math $math = null)
 {
     $size = $vch->getSize();
     if ($size > $maxNumSize) {
         throw new \RuntimeException('Script number overflow');
     }
     if ($fRequireMinimal && $size > 0) {
         $binary = $vch->getBinary();
         if (ord($binary[$size - 1]) & 0x7f === 0) {
             if ($size <= 1 || ord($binary[$size - 2]) & 0x80 === 0) {
                 throw new \RuntimeException('Non-minimally encoded script number');
             }
         }
     }
     $math = $math ?: Bitcoin::getMath();
     $number = new self(0, $math);
     $number->number = $number->parseBuffer($vch);
     return $number;
 }