/** * @param Parser $parser * @return \BitWasp\Bitcoin\Block\Block * @throws \BitWasp\Buffertools\Exceptions\ParserOutOfRange */ public function fromParser(Parser &$parser) { list($bytes, $blockSize) = $this->getHeaderTemplate()->parse($parser); if ($bytes->getHex() !== $this->network->getNetMagicBytes()) { throw new \RuntimeException('Block version bytes did not match network'); } return $this->blockSerializer->fromParser(new Parser($parser->readBytes($blockSize))); }
/** * {@inheritdoc} * @see \BitWasp\Buffertools\SerializableInterface::getBuffer() */ public function getBuffer() { $serializer = new HexBlockSerializer($this->math, new HexBlockHeaderSerializer(), new TransactionSerializer()); $hex = $serializer->serialize($this); return $hex; }
/** * @param $string * @param Math $math * @return Block */ public static function fromHex($string, Math $math = null) { $serializer = new HexBlockSerializer($math ?: Bitcoin::getMath(), new HexBlockHeaderSerializer(), new TransactionSerializer()); return $serializer->parse($string); }