@@ -260,156 +260,6 @@ else if (scriptType == ScriptType.P2SH)
260
260
}
261
261
}
262
262
263
- /**
264
- * Creates a scriptSig that can redeem a P2PKH output.
265
- * If given signature is null, incomplete scriptSig will be created with OP_0 instead of signature
266
- */
267
- // public static Script createInputScript(@Nullable TransactionSignature signature, ECKey pubKey) {
268
- // byte[] pubkeyBytes = pubKey.getPubKey();
269
- // byte[] sigBytes = signature != null ? signature.encodeToBitcoin() : new byte[]{};
270
- // return new ScriptBuilder().data(sigBytes).data(pubkeyBytes).build();
271
- // }
272
-
273
- /**
274
- * Creates a scriptSig that can redeem a P2PK output.
275
- * If given signature is null, incomplete scriptSig will be created with OP_0 instead of signature
276
- */
277
- // public static Script createInputScript(@Nullable TransactionSignature signature) {
278
- // byte[] sigBytes = signature != null ? signature.encodeToBitcoin() : new byte[]{};
279
- // return new ScriptBuilder().data(sigBytes).build();
280
- // }
281
-
282
- /** Creates a program that requires at least N of the given keys to sign, using OP_CHECKMULTISIG. */
283
- // public static Script createMultiSigOutputScript(int threshold, List<ECKey> pubkeys) {
284
- // checkArgument(threshold > 0);
285
- // checkArgument(threshold <= pubkeys.size());
286
- // checkArgument(pubkeys.size() <= 16); // That's the max we can represent with a single opcode.
287
- // ScriptBuilder builder = new ScriptBuilder();
288
- // builder.smallNum(threshold);
289
- // for (ECKey key : pubkeys) {
290
- // builder.data(key.getPubKey());
291
- // }
292
- // builder.smallNum(pubkeys.size());
293
- // builder.op(OP_CHECKMULTISIG);
294
- // return builder.build();
295
- // }
296
-
297
- /** Create a program that satisfies an OP_CHECKMULTISIG program. */
298
- // public static Script createMultiSigInputScript(List<TransactionSignature> signatures) {
299
- // List<byte[]> sigs = new ArrayList<>(signatures.size());
300
- // for (TransactionSignature signature : signatures) {
301
- // sigs.add(signature.encodeToBitcoin());
302
- // }
303
- //
304
- // return createMultiSigInputScriptBytes(sigs, null);
305
- // }
306
-
307
- /** Create a program that satisfies an OP_CHECKMULTISIG program. */
308
- // public static Script createMultiSigInputScript(TransactionSignature... signatures) {
309
- // return createMultiSigInputScript(Arrays.asList(signatures));
310
- // }
311
-
312
- /** Create a program that satisfies an OP_CHECKMULTISIG program, using pre-encoded signatures. */
313
- // public static Script createMultiSigInputScriptBytes(List<byte[]> signatures) {
314
- // return createMultiSigInputScriptBytes(signatures, null);
315
- // }
316
-
317
- /**
318
- * Create a program that satisfies a P2SH OP_CHECKMULTISIG program.
319
- * If given signature list is null, incomplete scriptSig will be created with OP_0 instead of signatures
320
- */
321
- // public static Script createP2SHMultiSigInputScript(@Nullable List<TransactionSignature> signatures,
322
- // Script multisigProgram) {
323
- // List<byte[]> sigs = new ArrayList<>();
324
- // if (signatures == null) {
325
- // // create correct number of empty signatures
326
- // int numSigs = multisigProgram.getNumberOfSignaturesRequiredToSpend();
327
- // for (int i = 0; i < numSigs; i++)
328
- // sigs.add(new byte[]{});
329
- // } else {
330
- // for (TransactionSignature signature : signatures) {
331
- // sigs.add(signature.encodeToBitcoin());
332
- // }
333
- // }
334
- // return createMultiSigInputScriptBytes(sigs, multisigProgram.getProgram());
335
- // }
336
-
337
- /**
338
- * Create a program that satisfies an OP_CHECKMULTISIG program, using pre-encoded signatures.
339
- * Optionally, appends the script program bytes if spending a P2SH output.
340
- */
341
- // public static Script createMultiSigInputScriptBytes(List<byte[]> signatures, @Nullable byte[] multisigProgramBytes) {
342
- // checkArgument(signatures.size() <= 16);
343
- // ScriptBuilder builder = new ScriptBuilder();
344
- // builder.smallNum(0); // Work around a bug in CHECKMULTISIG that is now a required part of the protocol.
345
- // for (byte[] signature : signatures)
346
- // builder.data(signature);
347
- // if (multisigProgramBytes!= null)
348
- // builder.data(multisigProgramBytes);
349
- // return builder.build();
350
- // }
351
-
352
- /**
353
- * Returns a copy of the given scriptSig with the signature inserted in the given position.
354
- *
355
- * This function assumes that any missing sigs have OP_0 placeholders. If given scriptSig already has all the signatures
356
- * in place, IllegalArgumentException will be thrown.
357
- *
358
- * @param targetIndex where to insert the signature
359
- * @param sigsPrefixCount how many items to copy verbatim (e.g. initial OP_0 for multisig)
360
- * @param sigsSuffixCount how many items to copy verbatim at end (e.g. redeemScript for P2SH)
361
- */
362
- // public static Script updateScriptWithSignature(Script scriptSig, byte[] signature, int targetIndex,
363
- // int sigsPrefixCount, int sigsSuffixCount) {
364
- // ScriptBuilder builder = new ScriptBuilder();
365
- // List<ScriptChunk> inputChunks = scriptSig.getChunks();
366
- // int totalChunks = inputChunks.size();
367
- //
368
- // // Check if we have a place to insert, otherwise just return given scriptSig unchanged.
369
- // // We assume here that OP_0 placeholders always go after the sigs, so
370
- // // to find if we have sigs missing, we can just check the chunk in latest sig position
371
- // boolean hasMissingSigs = inputChunks.get(totalChunks - sigsSuffixCount - 1).equalsOpCode(OP_0);
372
- // checkArgument(hasMissingSigs, "ScriptSig is already filled with signatures");
373
- //
374
- // // copy the prefix
375
- // for (ScriptChunk chunk: inputChunks.subList(0, sigsPrefixCount))
376
- // builder.addChunk(chunk);
377
- //
378
- // // copy the sigs
379
- // int pos = 0;
380
- // boolean inserted = false;
381
- // for (ScriptChunk chunk: inputChunks.subList(sigsPrefixCount, totalChunks - sigsSuffixCount)) {
382
- // if (pos == targetIndex) {
383
- // inserted = true;
384
- // builder.data(signature);
385
- // pos++;
386
- // }
387
- // if (!chunk.equalsOpCode(OP_0)) {
388
- // builder.addChunk(chunk);
389
- // pos++;
390
- // }
391
- // }
392
- //
393
- // // add OP_0's if needed, since we skipped them in the previous loop
394
- // while (pos < totalChunks - sigsPrefixCount - sigsSuffixCount) {
395
- // if (pos == targetIndex) {
396
- // inserted = true;
397
- // builder.data(signature);
398
- // }
399
- // else {
400
- // builder.addChunk(new ScriptChunk(OP_0, null));
401
- // }
402
- // pos++;
403
- // }
404
- //
405
- // // copy the suffix
406
- // for (ScriptChunk chunk: inputChunks.subList(totalChunks - sigsSuffixCount, totalChunks))
407
- // builder.addChunk(chunk);
408
- //
409
- // checkState(inserted);
410
- // return builder.build();
411
- // }
412
-
413
263
/** Creates a scriptPubKey that encodes payment to the given raw public key. */
414
264
public static Script createP2PKOutputScript (byte [] pubKey ) {
415
265
return new ScriptBuilder ().data (pubKey ).op (OP_CHECKSIG ).build ();
0 commit comments