Class Script
java.lang.Object
com.codename1.crypto.bitcoin.Script
A Bitcoin script: the locking scriptPubKey of an output, or the scriptSig, redeem and
witness scripts that unlock one. Immutable.
The standard output templates have factories (p2pkh(byte[]), p2wpkh(byte[]), p2tr(byte[])...) and
matching tests; builder() writes anything else with minimal pushes.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAppends opcodes and pushes to a script. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intOP_0, also the empty push.static final intOP_1;OP_2..OP_16follow it.static final intOP_16.static final intOP_1NEGATE.static final intOP_CHECKLOCKTIMEVERIFY.static final intOP_CHECKMULTISIG.static final intOP_CHECKSEQUENCEVERIFY.static final intOP_CHECKSIG.static final intOP_CHECKSIGADD, the Tapscript multisig opcode.static final intOP_DUP.static final intOP_EQUAL.static final intOP_EQUALVERIFY.static final intOP_HASH160.static final intOP_PUSHDATA1.static final intOP_PUSHDATA2.static final intOP_PUSHDATA4.static final intOP_RETURN. -
Method Summary
Modifier and TypeMethodDescriptionstatic Script.Builderbuilder()A builder that appends opcodes and minimal pushes.static Scriptempty()The empty script.booleanIndicates whether some other object is "equal to" this one.static ScriptWraps script bytes given in hex.byte[]The 20-byte hash a P2PKH or P2SH output commits to, the 20 or 32-byte program of a SegWit output, ornullfor any other script.byte[]The witness program of a SegWit output, ornull.intThe witness version of a SegWit output, or -1 when this is not one.inthashCode()Returns a hash code value for the object.booleanisP2pkh()Tells whether this is a P2PKH output.booleanisP2sh()Tells whether this is a P2SH output.booleanisP2tr()Tells whether this is a Taproot output.booleanisP2wpkh()Tells whether this is a P2WPKH output.booleanisP2wsh()Tells whether this is a P2WSH output.intlength()The script length in bytes.static Scriptmultisig(int m, byte[][] publicKeys) m <pubkey>... n OP_CHECKMULTISIG, the bare multisig redeem or witness script.static Scriptof(byte[] program) Wraps serialized script bytes.static ScriptopReturn(byte[] data) OP_RETURN <data>, a provably unspendable data carrier.static Scriptp2pkh(byte[] pubKeyHash20) OP_DUP OP_HASH160 <hash> OP_EQUALVERIFY OP_CHECKSIG.static Scriptp2sh(byte[] scriptHash20) OP_HASH160 <hash> OP_EQUAL.static Scriptp2tr(byte[] outputKey32) OP_1 <x-only key>, Taproot.static Scriptp2wpkh(byte[] pubKeyHash20) OP_0 <hash>, native SegWit v0 key hash.static Scriptp2wsh(byte[] scriptHash32) OP_0 <sha256(witnessScript)>, native SegWit v0 script hash.byte[]toBytes()A copy of the serialized script.toHex()The serialized script in hex.toString()Returns a string representation of the object.static Scriptwitness(int version, byte[] program) A witness output of any version (0 to 16) and program.
-
Field Details
-
OP_0
public static final int OP_0OP_0, also the empty push.- See Also:
-
OP_PUSHDATA1
public static final int OP_PUSHDATA1OP_PUSHDATA1.- See Also:
-
OP_PUSHDATA2
public static final int OP_PUSHDATA2OP_PUSHDATA2.- See Also:
-
OP_PUSHDATA4
public static final int OP_PUSHDATA4OP_PUSHDATA4.- See Also:
-
OP_1NEGATE
public static final int OP_1NEGATEOP_1NEGATE.- See Also:
-
OP_1
public static final int OP_1OP_1;OP_2..OP_16follow it.- See Also:
-
OP_16
public static final int OP_16OP_16.- See Also:
-
OP_RETURN
public static final int OP_RETURNOP_RETURN.- See Also:
-
OP_DUP
public static final int OP_DUPOP_DUP.- See Also:
-
OP_EQUAL
public static final int OP_EQUALOP_EQUAL.- See Also:
-
OP_EQUALVERIFY
public static final int OP_EQUALVERIFYOP_EQUALVERIFY.- See Also:
-
OP_HASH160
public static final int OP_HASH160OP_HASH160.- See Also:
-
OP_CHECKSIG
public static final int OP_CHECKSIGOP_CHECKSIG.- See Also:
-
OP_CHECKMULTISIG
public static final int OP_CHECKMULTISIGOP_CHECKMULTISIG.- See Also:
-
OP_CHECKLOCKTIMEVERIFY
public static final int OP_CHECKLOCKTIMEVERIFYOP_CHECKLOCKTIMEVERIFY.- See Also:
-
OP_CHECKSEQUENCEVERIFY
public static final int OP_CHECKSEQUENCEVERIFYOP_CHECKSEQUENCEVERIFY.- See Also:
-
OP_CHECKSIGADD
public static final int OP_CHECKSIGADDOP_CHECKSIGADD, the Tapscript multisig opcode.- See Also:
-
-
Method Details
-
empty
The empty script. -
of
Wraps serialized script bytes. -
fromHex
-
p2pkh
OP_DUP OP_HASH160 <hash> OP_EQUALVERIFY OP_CHECKSIG. -
p2sh
OP_HASH160 <hash> OP_EQUAL. -
p2wpkh
OP_0 <hash>, native SegWit v0 key hash. -
p2wsh
OP_0 <sha256(witnessScript)>, native SegWit v0 script hash. -
p2tr
OP_1 <x-only key>, Taproot. -
witness
A witness output of any version (0 to 16) and program. -
opReturn
OP_RETURN <data>, a provably unspendable data carrier. -
multisig
m <pubkey>... n OP_CHECKMULTISIG, the bare multisig redeem or witness script. -
builder
A builder that appends opcodes and minimal pushes. -
isP2pkh
public boolean isP2pkh()Tells whether this is a P2PKH output. -
isP2sh
public boolean isP2sh()Tells whether this is a P2SH output. -
isP2wpkh
public boolean isP2wpkh()Tells whether this is a P2WPKH output. -
isP2wsh
public boolean isP2wsh()Tells whether this is a P2WSH output. -
isP2tr
public boolean isP2tr()Tells whether this is a Taproot output. -
getWitnessVersion
public int getWitnessVersion()The witness version of a SegWit output, or -1 when this is not one. -
getWitnessProgram
public byte[] getWitnessProgram()The witness program of a SegWit output, ornull. -
getDestinationHash
public byte[] getDestinationHash()The 20-byte hash a P2PKH or P2SH output commits to, the 20 or 32-byte program of a SegWit output, ornullfor any other script. -
toBytes
public byte[] toBytes()A copy of the serialized script. -
length
public int length()The script length in bytes. -
toHex
The serialized script in hex. -
toString
Description copied from class:ObjectReturns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode()) -
equals
Description copied from class:ObjectIndicates whether some other object is "equal to" this one. The equals method implements an equivalence relation: It is reflexive: for any reference value x, x.equals(x) should return true. It is symmetric: for any reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true. It is transitive: for any reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true. It is consistent: for any reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the object is modified. For any non-null reference value x, x.equals(null) should return false. The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true). -
hashCode
public int hashCode()Description copied from class:ObjectReturns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable. The general contract of hashCode is: Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result. It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables. As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)
-