-
- All Implemented Interfaces:
-
java.lang.AutoCloseable,org.bitcoindevkit.Disposable,org.bitcoindevkit.TransactionInterface
public class Transaction implements Disposable, AutoCloseable, TransactionInterface
Bitcoin transaction. An authenticated movement of coins.
-
-
Constructor Summary
Constructors Constructor Description Transaction(ByteArray transactionBytes)Creates a new Transactioninstance from serialized transaction bytes.
-
Method Summary
Modifier and Type Method Description Unitdestroy()Unitclose()TxidcomputeTxid()Computes the Txid. WtxidcomputeWtxid()Compute the Wtxid, which includes the witness in the transaction hash. List<TxIn>input()List of transaction inputs. BooleanisCoinbase()Checks if this is a coinbase transaction. BooleanisExplicitlyRbf()Returns trueif the transaction itself opted in to be BIP-125-replaceable (RBF).BooleanisLockTimeEnabled()Returns trueif this transactions nLockTime is enabled (BIP-65).UIntlockTime()Block height or timestamp. List<TxOut>output()List of transaction outputs. ByteArrayserialize()Serialize transaction into consensus-valid format. ULongtotalSize()Returns the total transaction sizeTotal transaction size is the transaction size in bytes serialized as described in BIP144, including base data and witness data. Integerversion()The protocol version, is currently expected to be 1 or 2 (BIP 68). ULongvsize()Returns the "virtual size" (vsize) of this transaction. ULongweight()Returns the weight of this transaction, as defined by BIP-141. StringtoString()Booleanequals(Object other)-
-
Constructor Detail
-
Transaction
Transaction(ByteArray transactionBytes)
Creates a newTransactioninstance 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”).
-
isExplicitlyRbf
Boolean isExplicitlyRbf()
Returns
trueif the transaction itself opted in to be BIP-125-replaceable (RBF).Incorrectly relying on RBF may lead to monetary loss!
This does not cover the case where a transaction becomes replaceable due to ancestors being RBF. Please note that transactions may be replaced even if they do not include the RBF signal: https://bitcoinops.org/en/newsletters/2022/10/19/#transaction-replacement-option.
-
isLockTimeEnabled
Boolean isLockTimeEnabled()
Returns
trueif this transactions nLockTime is enabled (BIP-65).
-
lockTime
UInt lockTime()
Block height or timestamp. Transaction cannot be included in a block until this height/time.
/// ### Relevant BIPs
-
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.
-
vsize
ULong vsize()
Returns the "virtual size" (vsize) of this transaction.
Will be
ceil(weight / 4.0). Note this implements the virtual size as perBIP141, 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
0x00as amarkerfor 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.
-
-
-
-