Interface TransactionInterface
-
- All Implemented Interfaces:
public interface TransactionInterface
Bitcoin transaction. An authenticated movement of coins.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
TransactionInterface.Companion
-
Method Summary
Modifier and Type Method Description abstract String
computeTxid()
Computes the Txid. abstract List<TxIn>
input()
List of transaction inputs. abstract Boolean
isCoinbase()
Checks if this is a coinbase transaction. abstract Boolean
isExplicitlyRbf()
Returns true
if the transaction itself opted in to be BIP-125-replaceable (RBF).abstract Boolean
isLockTimeEnabled()
Returns true
if this transactions nLockTime is enabled (BIP-65).abstract UInt
lockTime()
Block height or timestamp. abstract List<TxOut>
output()
List of transaction outputs. abstract ByteArray
serialize()
Serialize transaction into consensus-valid format. abstract 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. abstract Integer
version()
The protocol version, is currently expected to be 1 or 2 (BIP 68). abstract ULong
vsize()
Returns the "virtual size" (vsize) of this transaction. abstract ULong
weight()
Returns the weight of this transaction, as defined by BIP-141.
-
-
-
Method Detail
-
computeTxid
abstract String computeTxid()
Computes the Txid. Hashes the transaction excluding the segwit data (i.e. the marker, flag bytes, and the witness fields themselves).
-
isCoinbase
abstract 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
abstract 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
abstract Boolean isLockTimeEnabled()
Returns
true
if this transactions nLockTime is enabled (BIP-65).
-
lockTime
abstract UInt lockTime()
Block height or timestamp. Transaction cannot be included in a block until this height/time.
/// ### Relevant BIPs
-
serialize
abstract 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
abstract 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
abstract Integer version()
The protocol version, is currently expected to be 1 or 2 (BIP 68).
-
vsize
abstract 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
abstract 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.
-
-