/**
  * 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();
 }
 /**
  * Create a program that satisfies an OP_CHECKMULTISIG program, using pre-encoded signatures.
  * Optionally, appends the script program bytes if spending a P2SH output.
  */
 public static Script createMultiSigInputScriptBytes(
     List<byte[]> signatures, @Nullable byte[] multisigProgramBytes) {
   checkArgument(signatures.size() <= 16);
   ScriptBuilder builder = new ScriptBuilder();
   builder.smallNum(
       0); // Work around a bug in CHECKMULTISIG that is now a required part of the protocol.
   for (byte[] signature : signatures) builder.data(signature);
   if (multisigProgramBytes != null) builder.data(multisigProgramBytes);
   return builder.build();
 }