pub struct Transaction(/* private fields */);Expand description
Bitcoin transaction. An authenticated movement of coins.
Implementations§
Source§impl Transaction
impl Transaction
Sourcepub fn new(transaction_bytes: Vec<u8>) -> Result<Self, TransactionError>
pub fn new(transaction_bytes: Vec<u8>) -> Result<Self, TransactionError>
Creates a new Transaction instance from serialized transaction bytes.
Sourcepub fn compute_txid(&self) -> Arc<Txid>
pub fn compute_txid(&self) -> Arc<Txid>
Computes the Txid. Hashes the transaction excluding the segwit data (i.e. the marker, flag bytes, and the witness fields themselves).
Sourcepub fn compute_wtxid(&self) -> Arc<Wtxid>
pub fn compute_wtxid(&self) -> Arc<Wtxid>
Compute the Wtxid, which includes the witness in the transaction hash.
Sourcepub fn weight(&self) -> u64
pub fn weight(&self) -> u64
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 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.
Sourcepub fn total_size(&self) -> u64
pub fn total_size(&self) -> u64
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.
Sourcepub fn vsize(&self) -> u64
pub fn vsize(&self) -> u64
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.
Virtual transaction size is defined as Transaction weight / 4 (rounded up to the next integer).
Sourcepub fn is_coinbase(&self) -> bool
pub fn is_coinbase(&self) -> bool
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”).
Sourcepub fn is_explicitly_rbf(&self) -> bool
pub fn is_explicitly_rbf(&self) -> bool
Returns true if the transaction itself opted in to be BIP-125-replaceable (RBF).
§Warning
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.
Sourcepub fn is_lock_time_enabled(&self) -> bool
pub fn is_lock_time_enabled(&self) -> bool
Returns true if this transactions nLockTime is enabled (BIP-65).
Sourcepub fn version(&self) -> i32
pub fn version(&self) -> i32
The protocol version, is currently expected to be 1 or 2 (BIP 68).
Sourcepub fn serialize(&self) -> Vec<u8> ⓘ
pub fn serialize(&self) -> Vec<u8> ⓘ
Serialize transaction into consensus-valid format. See https://docs.rs/bitcoin/latest/bitcoin/struct.Transaction.html#serialization-notes for more notes on transaction serialization.
Trait Implementations§
Source§impl Clone for Transaction
impl Clone for Transaction
Source§fn clone(&self) -> Transaction
fn clone(&self) -> Transaction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Transaction
impl Debug for Transaction
Source§impl Display for Transaction
impl Display for Transaction
Source§impl From<&Transaction> for Transaction
impl From<&Transaction> for Transaction
Source§impl From<&Transaction> for Transaction
impl From<&Transaction> for Transaction
Source§fn from(tx: &Transaction) -> Self
fn from(tx: &Transaction) -> Self
Source§impl From<Transaction> for Transaction
impl From<Transaction> for Transaction
Source§impl<UT> LiftRef<UT> for Transaction
impl<UT> LiftRef<UT> for Transaction
type LiftType = Arc<Transaction>
Source§impl<UT> LowerError<UT> for Transaction
impl<UT> LowerError<UT> for Transaction
Source§fn lower_error(obj: Self) -> RustBuffer
fn lower_error(obj: Self) -> RustBuffer
Source§impl<UT> LowerReturn<UT> for Transaction
impl<UT> LowerReturn<UT> for Transaction
Source§type ReturnType = <Arc<Transaction> as LowerReturn<UniFfiTag>>::ReturnType
type ReturnType = <Arc<Transaction> as LowerReturn<UniFfiTag>>::ReturnType
Source§fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>
§fn handle_failed_lift(
error: LiftArgsError,
) -> Result<Self::ReturnType, RustCallError>
fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>
Source§impl PartialEq for Transaction
impl PartialEq for Transaction
Source§impl<UT> TypeId<UT> for Transaction
impl<UT> TypeId<UT> for Transaction
const TYPE_ID_META: MetadataBuffer
impl Eq for Transaction
impl StructuralPartialEq for Transaction
Auto Trait Implementations§
impl Freeze for Transaction
impl RefUnwindSafe for Transaction
impl Send for Transaction
impl Sync for Transaction
impl Unpin for Transaction
impl UnwindSafe for Transaction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T>
unsafe fn consume_handle(handle: Handle) -> Arc<T>
Arc<> Read more