/**
  * 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();
 }