public function testPushDataOps() { $data = json_decode(file_get_contents(__DIR__ . "/data/pushdataops.json"), true); foreach ($data as $row) { $script = RawTransaction::pushdata($row['string']); $op = substr($script, 0, 2); $this->assertSame($row['op'], $op); } }
/** * add OP_RETURN output * * $data will be bin2hex and will be prefixed with a proper OP_PUSHDATA * * @param string $data * @param bool $allowNonStandard when TRUE will allow scriptPubKey > 40 bytes (so $data > 39 bytes) * @throws BlocktrailSDKException */ public function addOpReturn($data, $allowNonStandard = false) { $pushdata = RawTransaction::pushdata(bin2hex($data)); if (!$allowNonStandard && strlen($pushdata) / 2 > 40) { throw new BlocktrailSDKException("OP_RETURN data should be <= 39 bytes to remain standard!"); } $this->addOutput(['scriptPubKey' => self::OP_RETURN . RawTransaction::pushdata(bin2hex($data)), 'value' => 0]); }