Class TransactionWitness

java.lang.Object
org.bitcoinj.core.TransactionWitness

public class TransactionWitness extends Object
This structure contains data required to check transaction validity but not required to determine transaction effects. It is described as a number of byte vectors called "pushes". Those vectors are pushed to the script stack before script execution when validating a transaction.

For example, for inputs spending a P2WPKH output the witness consists of a signature and a public key – the same data that would have been pushed to the stack via a scriptSig for P2PKH.

Instances of this class are immutable.

See Also:
  • Field Details

  • Method Details

    • redeemP2WPKH

      public static TransactionWitness redeemP2WPKH(@Nullable TransactionSignature signature, ECKey pubKey)
      Creates the stack pushes necessary to redeem a P2WPKH output. If given signature is null, an empty push will be used as a placeholder.
    • redeemP2WSH

      public static TransactionWitness redeemP2WSH(Script witnessScript, TransactionSignature... signatures)
      Creates the stack pushes necessary to redeem a P2WSH output.
    • of

      public static TransactionWitness of(List<byte[]> pushes)
      Construct a transaction witness from a given list of arbitrary stack pushes.
      Parameters:
      pushes - list of pushes
      Returns:
      constructed transaction witness
    • of

      public static TransactionWitness of(byte[]... pushes)
      Construct a transaction witness from a given list of arbitrary stack pushes.
      Parameters:
      pushes - list of pushes
      Returns:
      constructed transaction witness
    • read

      public static TransactionWitness read(ByteBuffer payload) throws BufferUnderflowException
      Deserialize this transaction witness from a given payload.
      Parameters:
      payload - payload to deserialize from
      Returns:
      read message
      Throws:
      BufferUnderflowException - if the read message extends beyond the remaining bytes of the payload
    • getPush

      public byte[] getPush(int i)
      Get the stack push at a specified index.
      Parameters:
      i - index to get push at
      Returns:
      stack push
    • getPushCount

      public int getPushCount()
      Gets the number of stack pushes in this witness.
      Returns:
      number of pushes
    • write

      public ByteBuffer write(ByteBuffer buf) throws BufferOverflowException
      Write this transaction witness into the given buffer.
      Parameters:
      buf - buffer to write into
      Returns:
      the buffer
      Throws:
      BufferOverflowException - if the serialized data doesn't fit the remaining buffer
    • serialize

      public byte[] serialize()
      Allocates a byte array and writes this transaction witness into it.
      Returns:
      byte array containing the transaction witness
    • messageSize

      public int messageSize()
      Return the size of the serialized message. Note that if the message was deserialized from a payload, this size can differ from the size of the original payload.
      Returns:
      size of the serialized message in bytes
    • getMessageSize

      @Deprecated public int getMessageSize()
      Deprecated.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object