Package 

Class Transaction

    • Constructor Summary

      Constructors 
      Constructor Description
      Transaction(ByteArray transactionBytes) Creates a new Transaction instance from serialized transaction bytes.
    • Constructor Detail

      • Transaction

        Transaction(ByteArray transactionBytes)
        Creates a new Transaction instance from serialized transaction bytes.
    • Method Detail

      • computeTxid

         Txid computeTxid()

        Computes the Txid. Hashes the transaction excluding the segwit data (i.e. the marker, flag bytes, and the witness fields themselves).

      • computeWtxid

         Wtxid computeWtxid()

        Compute the Wtxid, which includes the witness in the transaction hash.

      • isCoinbase

         Boolean isCoinbase()

        Checks if this is a coinbase transaction. The first transaction in the block distributes the mining reward and is called the coinbase transaction. It is impossible to check if the transaction is first in the block, so this function checks the structure of the transaction instead - the previous output must be all-zeros (creates satoshis “out of thin air”).

      • serialize

         ByteArray serialize()

        Serialize transaction into consensus-valid format. See https://docs.rs/bitcoin/latest/bitcoin/struct.Transaction.html#serialization-notes for more notes on transaction serialization.

      • totalSize

         ULong totalSize()

        Returns the total transaction size

        Total transaction size is the transaction size in bytes serialized as described in BIP144, including base data and witness data.

      • version

         Integer version()

        The protocol version, is currently expected to be 1 or 2 (BIP 68).

      • vsize

         ULong vsize()

        Returns the "virtual size" (vsize) of this transaction.

        Will be ceil(weight / 4.0). Note this implements the virtual size as per BIP141, which is different to what is implemented in Bitcoin Core.

      • weight

         ULong weight()

        Returns the weight of this transaction, as defined by BIP-141.

        For transactions with an empty witness, this is simply the consensus-serialized size times four. For transactions with a witness, this is the non-witness consensus-serialized size multiplied by three plus the with-witness consensus-serialized size.

        For transactions with no inputs, this function will return a value 2 less than the actual weight of the serialized transaction. The reason is that zero-input transactions, post-segwit, cannot be unambiguously serialized; we make a choice that adds two extra bytes. For more details see BIP 141 which uses a "input count" of 0x00 as a marker for a Segwit-encoded transaction.

        If you need to use 0-input transactions, we strongly recommend you do so using the PSBT API. The unsigned transaction encoded within PSBT is always a non-segwit transaction and can therefore avoid this ambiguity.