/** * @param \BitWasp\Bitcoin\Script\Interpreter\Number $sequence * @return bool */ private function checkSequence(Number $sequence) { $txSequence = $this->transaction->getInput($this->inputToSign)->getSequence(); if ($this->transaction->getVersion() < 2) { return false; } if ($this->math->cmp($this->math->bitwiseAnd($txSequence, TransactionInputInterface::SEQUENCE_LOCKTIME_DISABLE_FLAG), 0) !== 0) { return 0; } $mask = $this->math->bitwiseOr(TransactionInputInterface::SEQUENCE_LOCKTIME_TYPE_FLAG, TransactionInputInterface::SEQUENCE_LOCKTIME_MASK); return $this->verifyLockTime($this->math->bitwiseAnd($txSequence, $mask), TransactionInputInterface::SEQUENCE_LOCKTIME_TYPE_FLAG, Number::int($this->math->bitwiseAnd($sequence->getInt(), $mask))); }
/** * @param Buffer $buffer * @return int */ private function parseBuffer(Buffer $buffer) { $size = $buffer->getSize(); if ($size === 0) { return '0'; } $chars = array_map(function ($binary) { return ord($binary); }, str_split($buffer->flip()->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[0] & 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; }