Package org.bitcoinj.script
Class ScriptPattern
java.lang.Object
org.bitcoinj.script.ScriptPattern
This is a Script pattern matcher with some typical script patterns
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
extractHashFromP2PKH
(Script script) Extract the pubkey hash from a P2PKH scriptPubKey.static byte[]
extractHashFromP2SH
(Script script) Extract the script hash from a P2SH scriptPubKey.static byte[]
extractHashFromP2WH
(Script script) Extract the pubkey hash from a P2WPKH or the script hash from a P2WSH scriptPubKey.static byte[]
extractKeyFromP2PK
(Script script) Extract the pubkey from a P2SH scriptPubKey.static byte[]
extractOutputKeyFromP2TR
(Script script) Extract the taproot output key from a P2TR scriptPubKey.static Sha256Hash
extractWitnessCommitmentHash
(Script script) Retrieves the hash from a segwit commitment (in an output of the coinbase transaction).static boolean
isOpReturn
(Script script) Returns whether this script is using OP_RETURN to store arbitrary data.static boolean
Returns true if this script is of the form<pubkey> OP_CHECKSIG
.static boolean
Returns true if this script is of the formDUP HASH160 <pubkey hash> EQUALVERIFY CHECKSIG
, ie, payment to an address like1VayNert3x1KzbpzMGt2qdqrAThiRovi8
.static boolean
Whether or not this is a scriptPubKey representing a P2SH output.static boolean
Returns true if this script is of the formOP_1 <pubkey>
.static boolean
Returns true if this script is of the formOP_0 <hash>
.static boolean
Returns true if this script is of the formOP_0 <hash>
and hash is 20 bytes long.static boolean
Returns true if this script is of the formOP_0 <hash>
and hash is 32 bytes long.static boolean
isSentToMultisig
(Script script) Returns whether this script matches the format used for m-of-n multisig outputs:[m] [keys...] [n] CHECKMULTISIG
static boolean
isWitnessCommitment
(Script script) Returns whether this script matches the pattern for a segwit commitment (in an output of the coinbase transaction).
-
Constructor Details
-
ScriptPattern
public ScriptPattern()
-
-
Method Details
-
isP2PKH
Returns true if this script is of the formDUP HASH160 <pubkey hash> EQUALVERIFY CHECKSIG
, ie, payment to an address like1VayNert3x1KzbpzMGt2qdqrAThiRovi8
. This form was originally intended for the case where you wish to send somebody money with a written code because their node is offline, but over time has become the standard way to make payments due to the short and recognizable base58 form addresses come in. -
extractHashFromP2PKH
Extract the pubkey hash from a P2PKH scriptPubKey. It's important that the script is in the correct form, so you will want to guard calls to this method withisP2PKH(Script)
. -
isP2SH
Whether or not this is a scriptPubKey representing a P2SH output. In such outputs, the logic that controls reclamation is not actually in the output at all. Instead there's just a hash, and it's up to the spending input to provide a program matching that hash.
P2SH is described by BIP16.
-
extractHashFromP2SH
Extract the script hash from a P2SH scriptPubKey. It's important that the script is in the correct form, so you will want to guard calls to this method withisP2SH(Script)
. -
isP2PK
Returns true if this script is of the form<pubkey> OP_CHECKSIG
. This form was originally intended for transactions where the peers talked to each other directly via TCP/IP, but has fallen out of favor with time due to that mode of operation being susceptible to man-in-the-middle attacks. It is still used in coinbase outputs and can be useful more exotic types of transaction, but today most payments are to addresses. -
extractKeyFromP2PK
Extract the pubkey from a P2SH scriptPubKey. It's important that the script is in the correct form, so you will want to guard calls to this method withisP2PK(Script)
. -
isP2WH
Returns true if this script is of the formOP_0 <hash>
. This can either be a P2WPKH or P2WSH scriptPubKey. These two script types were introduced with segwit. -
isP2WPKH
Returns true if this script is of the formOP_0 <hash>
and hash is 20 bytes long. This can only be a P2WPKH scriptPubKey. This script type was introduced with segwit. -
isP2WSH
Returns true if this script is of the formOP_0 <hash>
and hash is 32 bytes long. This can only be a P2WSH scriptPubKey. This script type was introduced with segwit. -
extractHashFromP2WH
Extract the pubkey hash from a P2WPKH or the script hash from a P2WSH scriptPubKey. It's important that the script is in the correct form, so you will want to guard calls to this method withisP2WH(Script)
. -
isP2TR
Returns true if this script is of the formOP_1 <pubkey>
. This is a P2TR scriptPubKey. This script type was introduced with taproot. -
extractOutputKeyFromP2TR
Extract the taproot output key from a P2TR scriptPubKey. It's important that the script is in the correct form, so you will want to guard calls to this method withisP2TR(Script)
. -
isSentToMultisig
Returns whether this script matches the format used for m-of-n multisig outputs:[m] [keys...] [n] CHECKMULTISIG
-
isOpReturn
Returns whether this script is using OP_RETURN to store arbitrary data. -
isWitnessCommitment
Returns whether this script matches the pattern for a segwit commitment (in an output of the coinbase transaction). See BIP141. -
extractWitnessCommitmentHash
Retrieves the hash from a segwit commitment (in an output of the coinbase transaction). You will want to guard calls to this method withisWitnessCommitment(Script)
. See BIP141.
-