Introduce TxInExt trait
In preparation for moving the `TxIn` over to `primitives` introduce an extension trait.
This commit is contained in:
parent
b7e6c698f8
commit
4c5dba82f4
|
@ -129,7 +129,9 @@ impl TxIn {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TxIn {
|
crate::internal_macros::define_extension_trait! {
|
||||||
|
/// Extension functionality for the [`TxIn`] type.
|
||||||
|
pub trait TxInExt impl for TxIn {
|
||||||
/// Returns true if this input enables the [`absolute::LockTime`] (aka `nLockTime`) of its
|
/// Returns true if this input enables the [`absolute::LockTime`] (aka `nLockTime`) of its
|
||||||
/// [`Transaction`].
|
/// [`Transaction`].
|
||||||
///
|
///
|
||||||
|
@ -139,7 +141,7 @@ impl TxIn {
|
||||||
/// this input then the script execution will fail [BIP-0065].
|
/// this input then the script execution will fail [BIP-0065].
|
||||||
///
|
///
|
||||||
/// [BIP-65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki)
|
/// [BIP-65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki)
|
||||||
pub fn enables_lock_time(&self) -> bool { self.sequence != Sequence::MAX }
|
fn enables_lock_time(&self) -> bool { self.sequence != Sequence::MAX }
|
||||||
|
|
||||||
/// The weight of the TxIn when it's included in a legacy transaction (i.e., a transaction
|
/// The weight of the TxIn when it's included in a legacy transaction (i.e., a transaction
|
||||||
/// having only legacy inputs).
|
/// having only legacy inputs).
|
||||||
|
@ -150,7 +152,7 @@ impl TxIn {
|
||||||
/// Keep in mind that when adding a TxIn to a transaction, the total weight of the transaction
|
/// Keep in mind that when adding a TxIn to a transaction, the total weight of the transaction
|
||||||
/// might increase more than `TxIn::legacy_weight`. This happens when the new input added causes
|
/// might increase more than `TxIn::legacy_weight`. This happens when the new input added causes
|
||||||
/// the input length `VarInt` to increase its encoding length.
|
/// the input length `VarInt` to increase its encoding length.
|
||||||
pub fn legacy_weight(&self) -> Weight {
|
fn legacy_weight(&self) -> Weight {
|
||||||
Weight::from_non_witness_data_size(self.base_size().to_u64())
|
Weight::from_non_witness_data_size(self.base_size().to_u64())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +167,7 @@ impl TxIn {
|
||||||
/// - the new input added causes the input length `VarInt` to increase its encoding length
|
/// - the new input added causes the input length `VarInt` to increase its encoding length
|
||||||
/// - the new input is the first segwit input added - this will add an additional 2WU to the
|
/// - the new input is the first segwit input added - this will add an additional 2WU to the
|
||||||
/// transaction weight to take into account the segwit marker
|
/// transaction weight to take into account the segwit marker
|
||||||
pub fn segwit_weight(&self) -> Weight {
|
fn segwit_weight(&self) -> Weight {
|
||||||
Weight::from_non_witness_data_size(self.base_size().to_u64())
|
Weight::from_non_witness_data_size(self.base_size().to_u64())
|
||||||
+ Weight::from_witness_data_size(self.witness.size().to_u64())
|
+ Weight::from_witness_data_size(self.witness.size().to_u64())
|
||||||
}
|
}
|
||||||
|
@ -173,7 +175,7 @@ impl TxIn {
|
||||||
/// Returns the base size of this input.
|
/// Returns the base size of this input.
|
||||||
///
|
///
|
||||||
/// Base size excludes the witness data (see [`Self::total_size`]).
|
/// Base size excludes the witness data (see [`Self::total_size`]).
|
||||||
pub fn base_size(&self) -> usize {
|
fn base_size(&self) -> usize {
|
||||||
let mut size = OutPoint::SIZE;
|
let mut size = OutPoint::SIZE;
|
||||||
|
|
||||||
size += compact_size::encoded_size(self.script_sig.len());
|
size += compact_size::encoded_size(self.script_sig.len());
|
||||||
|
@ -185,7 +187,8 @@ impl TxIn {
|
||||||
/// Returns the total number of bytes that this input contributes to a transaction.
|
/// Returns the total number of bytes that this input contributes to a transaction.
|
||||||
///
|
///
|
||||||
/// Total size includes the witness data (for base size see [`Self::base_size`]).
|
/// Total size includes the witness data (for base size see [`Self::base_size`]).
|
||||||
pub fn total_size(&self) -> usize { self.base_size() + self.witness.size() }
|
fn total_size(&self) -> usize { self.base_size() + self.witness.size() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bitcoin transaction output.
|
/// Bitcoin transaction output.
|
||||||
|
@ -1338,6 +1341,7 @@ mod sealed {
|
||||||
impl Sealed for super::Txid {}
|
impl Sealed for super::Txid {}
|
||||||
impl Sealed for super::Wtxid {}
|
impl Sealed for super::Wtxid {}
|
||||||
impl Sealed for super::OutPoint {}
|
impl Sealed for super::OutPoint {}
|
||||||
|
impl Sealed for super::TxIn {}
|
||||||
impl Sealed for super::TxOut {}
|
impl Sealed for super::TxOut {}
|
||||||
impl Sealed for super::Version {}
|
impl Sealed for super::Version {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue