Class Transaction
-
- 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(Pointer pointer)
Transaction(NoPointer noPointer)
This constructor can be used to instantiate a fake object. Transaction(ByteArray transactionBytes)
Creates a new Transaction
instance from serialized transaction bytes.
-
Method Summary
Modifier and Type Method Description Unit
destroy()
Unit
close()
final Pointer
uniffiClonePointer()
String
computeTxid()
Computes the Txid. List<TxIn>
input()
List of transaction inputs. Boolean
isCoinbase()
Checks if this is a coinbase transaction. Boolean
isExplicitlyRbf()
Returns true
if the transaction itself opted in to be BIP-125-replaceable (RBF).Boolean
isLockTimeEnabled()
Returns true
if this transactions nLockTime is enabled (BIP-65).UInt
lockTime()
Block height or timestamp. List<TxOut>
output()
List of transaction outputs. ByteArray
serialize()
Serialize transaction into consensus-valid format. ULong
totalSize()
Returns the total transaction sizeTotal transaction size is the transaction size in bytes serialized as described in BIP144, including base data and witness data. Integer
version()
The protocol version, is currently expected to be 1 or 2 (BIP 68). ULong
vsize()
Returns the "virtual size" (vsize) of this transaction. ULong
weight()
Returns the weight of this transaction, as defined by BIP-141.
-
-
-
Constructor Detail
-
Transaction
Transaction(Pointer pointer)
-
Transaction
Transaction(NoPointer noPointer)
This constructor can be used to instantiate a fake object.
-
Transaction
Transaction(ByteArray transactionBytes)
Creates a newTransaction
instance from serialized transaction bytes.
-
-
Method Detail
-
uniffiClonePointer
final Pointer uniffiClonePointer()
-
computeTxid
String computeTxid()
Computes the Txid. Hashes the transaction excluding the segwit data (i.e. the marker, flag bytes, and the witness fields themselves).
-
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
true
if 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
true
if 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.Virtual transaction size is defined as Transaction weight / 4 (rounded up to the next integer).
-
weight
ULong weight()
Returns the weight of this transaction, as defined by BIP-141.
Transaction weight is defined as Base transaction size * 3 + Total transaction size (ie. the same method as calculating Block weight from Base size and Total size).
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 amarker
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.
-
-