/** * Creates a program that requires at least N of the given keys to sign, using OP_CHECKMULTISIG. */ public static Script createMultiSigOutputScript(int threshold, List<ECKey> pubkeys) { checkArgument(threshold > 0); checkArgument(threshold <= pubkeys.size()); checkArgument(pubkeys.size() <= 16); // That's the max we can represent with a single opcode. ScriptBuilder builder = new ScriptBuilder(); builder.smallNum(threshold); for (ECKey key : pubkeys) { builder.data(key.getPubKey()); } builder.smallNum(pubkeys.size()); builder.op(OP_CHECKMULTISIG); return builder.build(); }
/** * Creates a scriptSig that can redeem a pay-to-address output. If given signature is null, * incomplete scriptSig will be created with OP_0 instead of signature */ public static Script createInputScript(@Nullable TransactionSignature signature, ECKey pubKey) { byte[] pubkeyBytes = pubKey.getPubKey(); byte[] sigBytes = signature != null ? signature.encodeToPeercoin() : new byte[] {}; return new ScriptBuilder().data(sigBytes).data(pubkeyBytes).build(); }
/** Creates a scriptPubKey that encodes payment to the given raw public key. */ public static Script createOutputScript(ECKey key) { return new ScriptBuilder().data(key.getPubKey()).op(OP_CHECKSIG).build(); }