Class ScriptPattern

java.lang.Object
org.bitcoinj.script.ScriptPattern

public class ScriptPattern extends Object
This is a Script pattern matcher with some typical script patterns
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    Extract the pubkey hash from a P2PKH scriptPubKey.
    static byte[]
    Extract the script hash from a P2SH scriptPubKey.
    static byte[]
    Extract the pubkey hash from a P2WPKH or the script hash from a P2WSH scriptPubKey.
    static byte[]
    Extract the pubkey from a P2SH scriptPubKey.
    static byte[]
    Extract the taproot output key from a P2TR scriptPubKey.
    static Sha256Hash
    Retrieves the hash from a segwit commitment (in an output of the coinbase transaction).
    static boolean
    Returns whether this script is using OP_RETURN to store arbitrary data.
    static boolean
    isP2PK(Script script)
    Returns true if this script is of the form <pubkey> OP_CHECKSIG.
    static boolean
    isP2PKH(Script script)
    Returns true if this script is of the form DUP HASH160 <pubkey hash> EQUALVERIFY CHECKSIG, ie, payment to an address like 1VayNert3x1KzbpzMGt2qdqrAThiRovi8.
    static boolean
    isP2SH(Script script)
    Whether or not this is a scriptPubKey representing a P2SH output.
    static boolean
    isP2TR(Script script)
    Returns true if this script is of the form OP_1 <pubkey>.
    static boolean
    isP2WH(Script script)
    Returns true if this script is of the form OP_0 <hash>.
    static boolean
    isP2WPKH(Script script)
    Returns true if this script is of the form OP_0 <hash> and hash is 20 bytes long.
    static boolean
    isP2WSH(Script script)
    Returns true if this script is of the form OP_0 <hash> and hash is 32 bytes long.
    static boolean
    Returns whether this script matches the format used for m-of-n multisig outputs: [m] [keys...] [n] CHECKMULTISIG
    static boolean
    Returns whether this script matches the pattern for a segwit commitment (in an output of the coinbase transaction).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ScriptPattern

      public ScriptPattern()
  • Method Details

    • isP2PKH

      public static boolean isP2PKH(Script script)
      Returns true if this script is of the form DUP HASH160 <pubkey hash> EQUALVERIFY CHECKSIG, ie, payment to an address like 1VayNert3x1KzbpzMGt2qdqrAThiRovi8. 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

      public static byte[] extractHashFromP2PKH(Script script)
      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 with isP2PKH(Script).
    • isP2SH

      public static boolean isP2SH(Script script)

      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

      public static byte[] extractHashFromP2SH(Script script)
      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 with isP2SH(Script).
    • isP2PK

      public static boolean isP2PK(Script script)
      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

      public static byte[] extractKeyFromP2PK(Script script)
      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 with isP2PK(Script).
    • isP2WH

      public static boolean isP2WH(Script script)
      Returns true if this script is of the form OP_0 <hash>. This can either be a P2WPKH or P2WSH scriptPubKey. These two script types were introduced with segwit.
    • isP2WPKH

      public static boolean isP2WPKH(Script script)
      Returns true if this script is of the form OP_0 <hash> and hash is 20 bytes long. This can only be a P2WPKH scriptPubKey. This script type was introduced with segwit.
    • isP2WSH

      public static boolean isP2WSH(Script script)
      Returns true if this script is of the form OP_0 <hash> and hash is 32 bytes long. This can only be a P2WSH scriptPubKey. This script type was introduced with segwit.
    • extractHashFromP2WH

      public static byte[] extractHashFromP2WH(Script script)
      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 with isP2WH(Script).
    • isP2TR

      public static boolean isP2TR(Script script)
      Returns true if this script is of the form OP_1 <pubkey>. This is a P2TR scriptPubKey. This script type was introduced with taproot.
    • extractOutputKeyFromP2TR

      public static byte[] extractOutputKeyFromP2TR(Script script)
      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 with isP2TR(Script).
    • isSentToMultisig

      public static boolean isSentToMultisig(Script script)
      Returns whether this script matches the format used for m-of-n multisig outputs: [m] [keys...] [n] CHECKMULTISIG
    • isOpReturn

      public static boolean isOpReturn(Script script)
      Returns whether this script is using OP_RETURN to store arbitrary data.
    • isWitnessCommitment

      public static boolean isWitnessCommitment(Script script)
      Returns whether this script matches the pattern for a segwit commitment (in an output of the coinbase transaction).
    • extractWitnessCommitmentHash

      public static Sha256Hash extractWitnessCommitmentHash(Script script)
      Retrieves the hash from a segwit commitment (in an output of the coinbase transaction).