public class ScriptBuilder
extends java.lang.Object
Tools for the construction of commonly used script types. You don't normally need this as it's hidden behind
convenience methods on Transaction
, but they are useful when working with the
protocol at a lower level.
Constructor and Description |
---|
ScriptBuilder()
Creates a fresh ScriptBuilder with an empty program.
|
ScriptBuilder(Script template)
Creates a fresh ScriptBuilder with the given program as the starting point.
|
Modifier and Type | Method and Description |
---|---|
ScriptBuilder |
addChunk(int index,
ScriptChunk chunk)
Adds the given chunk at the given index in the program
|
ScriptBuilder |
addChunk(ScriptChunk chunk)
Adds the given chunk to the end of the program
|
protected ScriptBuilder |
bigNum(int index,
long num)
Adds the given number as a push data chunk to the given index in the program.
|
protected ScriptBuilder |
bigNum(long num)
Adds the given number as a push data chunk.
|
Script |
build()
Creates a new immutable Script based on the state of the builder.
|
static Script |
createCLTVPaymentChannelInput(byte[] from,
byte[] to) |
static Script |
createCLTVPaymentChannelInput(TransactionSignature from,
TransactionSignature to) |
static Script |
createCLTVPaymentChannelOutput(java.math.BigInteger time,
ECKey from,
ECKey to) |
static Script |
createCLTVPaymentChannelP2SHInput(byte[] from,
byte[] to,
Script redeemScript) |
static Script |
createCLTVPaymentChannelP2SHRefund(TransactionSignature signature,
Script redeemScript) |
static Script |
createCLTVPaymentChannelRefund(TransactionSignature signature) |
static Script |
createEmpty()
Creates an empty script.
|
static Script |
createInputScript(TransactionSignature signature)
Creates a scriptSig that can redeem a P2PK output.
|
static Script |
createInputScript(TransactionSignature signature,
ECKey pubKey)
Creates a scriptSig that can redeem a P2PKH output.
|
static Script |
createMultiSigInputScript(java.util.List<TransactionSignature> signatures)
Create a program that satisfies an OP_CHECKMULTISIG program.
|
static Script |
createMultiSigInputScript(TransactionSignature... signatures)
Create a program that satisfies an OP_CHECKMULTISIG program.
|
static Script |
createMultiSigInputScriptBytes(java.util.List<byte[]> signatures)
Create a program that satisfies an OP_CHECKMULTISIG program, using pre-encoded signatures.
|
static Script |
createMultiSigInputScriptBytes(java.util.List<byte[]> signatures,
byte[] multisigProgramBytes)
Create a program that satisfies an OP_CHECKMULTISIG program, using pre-encoded signatures.
|
static Script |
createMultiSigOutputScript(int threshold,
java.util.List<ECKey> pubkeys)
Creates a program that requires at least N of the given keys to sign, using OP_CHECKMULTISIG.
|
static Script |
createOpReturnScript(byte[] data)
Creates a script of the form OP_RETURN [data].
|
static Script |
createOutputScript(Address to)
Creates a scriptPubKey that encodes payment to the given address.
|
static Script |
createP2PKHOutputScript(byte[] hash)
Creates a scriptPubKey that sends to the given public key hash.
|
static Script |
createP2PKHOutputScript(ECKey key)
Creates a scriptPubKey that sends to the given public key.
|
static Script |
createP2PKOutputScript(byte[] pubKey)
Creates a scriptPubKey that encodes payment to the given raw public key.
|
static Script |
createP2PKOutputScript(ECKey pubKey)
Creates a scriptPubKey that encodes payment to the given raw public key.
|
static Script |
createP2SHMultiSigInputScript(java.util.List<TransactionSignature> signatures,
Script multisigProgram)
Create a program that satisfies a P2SH OP_CHECKMULTISIG program.
|
static Script |
createP2SHOutputScript(byte[] hash)
Creates a scriptPubKey that sends to the given script hash.
|
static Script |
createP2SHOutputScript(int threshold,
java.util.List<ECKey> pubkeys)
Creates a P2SH output script with given public keys and threshold.
|
static Script |
createP2SHOutputScript(Script redeemScript)
Creates a scriptPubKey for the given redeem script.
|
static Script |
createP2WPKHOutputScript(byte[] hash)
Creates a segwit scriptPubKey that sends to the given public key hash.
|
static Script |
createP2WPKHOutputScript(ECKey key)
Creates a segwit scriptPubKey that sends to the given public key.
|
static Script |
createP2WSHOutputScript(byte[] hash)
Creates a segwit scriptPubKey that sends to the given script hash.
|
static Script |
createP2WSHOutputScript(Script redeemScript)
Creates a segwit scriptPubKey for the given redeem script.
|
static Script |
createRedeemScript(int threshold,
java.util.List<ECKey> pubkeys)
Creates redeem script with given public keys and threshold.
|
ScriptBuilder |
data(byte[] data)
Adds a copy of the given byte array as a data element (i.e.
|
ScriptBuilder |
data(int index,
byte[] data)
Adds a copy of the given byte array as a data element (i.e.
|
ScriptBuilder |
number(int index,
long num)
Adds the given number to the given index in the program.
|
ScriptBuilder |
number(long num)
Adds the given number to the end of the program.
|
ScriptBuilder |
op(int opcode)
Adds the given opcode to the end of the program.
|
ScriptBuilder |
op(int index,
int opcode)
Adds the given opcode to the given index in the program
|
ScriptBuilder |
opFalse()
Adds false to the end of the program.
|
ScriptBuilder |
opFalse(int index)
Adds false to the given index in the program.
|
ScriptBuilder |
opTrue()
Adds true to the end of the program.
|
ScriptBuilder |
opTrue(int index)
Adds true to the given index in the program.
|
ScriptBuilder |
smallNum(int num)
Adds the given number as a OP_N opcode to the end of the program.
|
ScriptBuilder |
smallNum(int index,
int num)
Adds the given number as a OP_N opcode to the given index in the program.
|
static Script |
updateScriptWithSignature(Script scriptSig,
byte[] signature,
int targetIndex,
int sigsPrefixCount,
int sigsSuffixCount)
Returns a copy of the given scriptSig with the signature inserted in the given position.
|
public ScriptBuilder()
public ScriptBuilder(Script template)
public ScriptBuilder addChunk(ScriptChunk chunk)
public ScriptBuilder addChunk(int index, ScriptChunk chunk)
public ScriptBuilder op(int opcode)
public ScriptBuilder op(int index, int opcode)
public ScriptBuilder data(byte[] data)
public ScriptBuilder data(int index, byte[] data)
public ScriptBuilder number(long num)
public ScriptBuilder number(int index, long num)
public ScriptBuilder smallNum(int num)
number(long)
protected ScriptBuilder bigNum(long num)
number(long)
public ScriptBuilder smallNum(int index, int num)
number(long)
protected ScriptBuilder bigNum(int index, long num)
number(long)
public ScriptBuilder opTrue()
public ScriptBuilder opTrue(int index)
index
- at which insert truepublic ScriptBuilder opFalse()
public ScriptBuilder opFalse(int index)
index
- at which insert truepublic Script build()
public static Script createEmpty()
public static Script createOutputScript(Address to)
public static Script createInputScript(@Nullable TransactionSignature signature, ECKey pubKey)
public static Script createInputScript(@Nullable TransactionSignature signature)
public static Script createMultiSigOutputScript(int threshold, java.util.List<ECKey> pubkeys)
public static Script createMultiSigInputScript(java.util.List<TransactionSignature> signatures)
public static Script createMultiSigInputScript(TransactionSignature... signatures)
public static Script createMultiSigInputScriptBytes(java.util.List<byte[]> signatures)
public static Script createP2SHMultiSigInputScript(@Nullable java.util.List<TransactionSignature> signatures, Script multisigProgram)
public static Script createMultiSigInputScriptBytes(java.util.List<byte[]> signatures, @Nullable byte[] multisigProgramBytes)
public static Script updateScriptWithSignature(Script scriptSig, byte[] signature, int targetIndex, int sigsPrefixCount, int sigsSuffixCount)
targetIndex
- where to insert the signaturesigsPrefixCount
- how many items to copy verbatim (e.g. initial OP_0 for multisig)sigsSuffixCount
- how many items to copy verbatim at end (e.g. redeemScript for P2SH)public static Script createP2PKOutputScript(byte[] pubKey)
public static Script createP2PKOutputScript(ECKey pubKey)
public static Script createP2PKHOutputScript(byte[] hash)
public static Script createP2PKHOutputScript(ECKey key)
public static Script createP2WPKHOutputScript(byte[] hash)
public static Script createP2WPKHOutputScript(ECKey key)
public static Script createP2SHOutputScript(byte[] hash)
public static Script createP2SHOutputScript(Script redeemScript)
public static Script createP2WSHOutputScript(byte[] hash)
public static Script createP2WSHOutputScript(Script redeemScript)
public static Script createP2SHOutputScript(int threshold, java.util.List<ECKey> pubkeys)
public static Script createRedeemScript(int threshold, java.util.List<ECKey> pubkeys)
public static Script createOpReturnScript(byte[] data)
public static Script createCLTVPaymentChannelOutput(java.math.BigInteger time, ECKey from, ECKey to)
public static Script createCLTVPaymentChannelRefund(TransactionSignature signature)
public static Script createCLTVPaymentChannelP2SHRefund(TransactionSignature signature, Script redeemScript)
public static Script createCLTVPaymentChannelP2SHInput(byte[] from, byte[] to, Script redeemScript)
public static Script createCLTVPaymentChannelInput(TransactionSignature from, TransactionSignature to)
public static Script createCLTVPaymentChannelInput(byte[] from, byte[] to)