public function testFixedLengthString() { $txin = '58891e8f28100642464417f53845c3953a43e31b35d061bdbf6ca3a64fffabb8000000008c493046022100a9d501a6f59c45a24e65e5030903cfd80ba33910f24d6a505961d64fa5042b4f02210089fa7cc00ab2b5fc15499fa259a057e6d0911d4e849f1720cc6bc58e941fe7e20141041a2756dd506e45a1142c7f7f03ae9d3d9954f8543f4c3ca56f025df66f1afcba6086cec8d4135cbb5f5f1d731f25ba0884fc06945c9bbf69b9b543ca91866e79ffffffff'; $txinBuf = Buffer::hex($txin); $txinParser = new Parser($txinBuf); $math = EccFactory::getAdapter(); $template = new Template([new ByteString($math, 32, ByteOrder::LE), new Uint32($math, ByteOrder::LE), new VarString(new VarInt($math))]); $out = $template->parse($txinParser); /** * @var Buffer $txhash */ $txhash = $out[0]; /** * @var Buffer $script */ $script = $out[2]; $this->assertEquals('b8abff4fa6a36cbfbd61d0351be3433a95c34538f5174446420610288f1e8958', $txhash->getHex()); $this->assertEquals(0, $out[1]); $this->assertEquals('493046022100a9d501a6f59c45a24e65e5030903cfd80ba33910f24d6a505961d64fa5042b4f02210089fa7cc00ab2b5fc15499fa259a057e6d0911d4e849f1720cc6bc58e941fe7e20141041a2756dd506e45a1142c7f7f03ae9d3d9954f8543f4c3ca56f025df66f1afcba6086cec8d4135cbb5f5f1d731f25ba0884fc06945c9bbf69b9b543ca91866e79', $script->getHex()); }
/** * Add a vector serializer to the template. A $readHandler must be provided if the * template will be used to deserialize a vector, since it's contents are not known. * * The $readHandler should operate on the parser reference, reading the bytes for each * item in the collection. * * @param callable $readHandler * @return $this */ public function vector(callable $readHandler) { $this->template->addItem(new Vector(new VarInt($this->math), $readHandler)); return $this; }