/**
  * @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)));
 }
示例#2
0
 /**
  * {@inheritdoc}
  * @see \BitWasp\Buffertools\SerializableInterface::getBuffer()
  */
 public function getBuffer()
 {
     $serializer = new HexBlockSerializer($this->math, new HexBlockHeaderSerializer(), new TransactionSerializer());
     $hex = $serializer->serialize($this);
     return $hex;
 }
示例#3
0
 /**
  * @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);
 }