/** * @param int $m * @param PublicKeyInterface[] $keys * @param bool|true $sort * @return ScriptCreator|Script */ public function multisig($m, array $keys = [], $sort = true) { $n = count($keys); if ($m > $n) { throw new \LogicException('Required number of sigs exceeds number of public keys'); } if ($n > 16) { throw new \LogicException('Number of public keys is greater than 16'); } if ($sort) { $keys = Buffertools::sort($keys); } $opM = \BitWasp\Bitcoin\Script\encodeOpN($m); $opN = \BitWasp\Bitcoin\Script\encodeOpN($n); $script = ScriptFactory::create(); foreach ($keys as $key) { if (!$key instanceof PublicKeyInterface) { throw new \LogicException('Values in $keys[] must be a PublicKey'); } $script->push($key->getBuffer()); } $keyBuf = $script->getScript()->getBuffer(); $script = new Script(new Buffer(chr($opM) . $keyBuf->getBinary() . chr($opN) . chr(Opcodes::OP_CHECKMULTISIG))); return $script; }
/** * @param int $n * @return $this */ public function int($n) { if ($n === 0) { $this->script .= chr(Opcodes::OP_0); } else { if ($n === -1 || $n >= 1 && $n <= 16) { $this->script .= chr(\BitWasp\Bitcoin\Script\encodeOpN($n)); } else { $this->script .= Number::int($n)->getBinary(); } } return $this; }