/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Integer too large, exceeds 64 bit */ public function testSolveReadTooLong() { $math = EccFactory::getAdapter(); $varint = new VarInt($math); $disallowed = $math->add($math->pow(2, 64), 1); $varint->solveReadSize($disallowed); }
/** * {@inheritdoc} * @see \BitWasp\Buffertools\Types\TypeInterface::write() * @param Parser $parser * @return \BitWasp\Buffertools\Buffer * @throws \BitWasp\Buffertools\Exceptions\ParserOutOfRange * @throws \Exception */ public function read(Parser &$parser) { $length = $this->varint->read($parser); if ($this->varint->getMath()->cmp($length, 0) == 0) { return new Buffer(); } return $parser->readBytes($length); }
/** * @param Parser $parser * @return Transaction */ public function fromParser(Parser $parser) { $math = Bitcoin::getMath(); $int32le = new Int32($math, ByteOrder::LE); $uint32le = new Uint32($math, ByteOrder::LE); $varint = new VarInt($math, ByteOrder::LE); $version = $int32le->read($parser); $vin = []; $vinCount = $varint->read($parser); for ($i = 0; $i < $vinCount; $i++) { $vin[] = $this->inputSerializer->fromParser($parser); } $vout = []; $flags = 0; if (count($vin) == 0) { $flags = (int) $varint->read($parser); if ($flags != 0) { $vinCount = $varint->read($parser); for ($i = 0; $i < $vinCount; $i++) { $vin[] = $this->inputSerializer->fromParser($parser); } $voutCount = $varint->read($parser); for ($i = 0; $i < $voutCount; $i++) { $vout[] = $this->outputSerializer->fromParser($parser); } } } else { $voutCount = $varint->read($parser); for ($i = 0; $i < $voutCount; $i++) { $vout[] = $this->outputSerializer->fromParser($parser); } } $vwit = []; if ($flags & 1) { $flags ^= 1; $witCount = count($vin); for ($i = 0; $i < $witCount; $i++) { $vectorCount = $varint->read($parser); $vwit[] = $this->witnessSerializer->fromParser($parser, $vectorCount); } } if ($flags) { throw new \RuntimeException('Flags byte was 0'); } $lockTime = $uint32le->read($parser); return new Transaction($version, new TransactionInputCollection($vin), new TransactionOutputCollection($vout), new TransactionWitnessCollection($vwit), $lockTime); }