Merge rust-bitcoin/rust-bitcoin#3254: Introduce `TxOutExt`
b61adf7ca4
Introduce TxOutExt trait (Tobin C. Harding)8b089ffe40
Run the formatter (Tobin C. Harding)02c7d504fa
Add tmp module around TxOut impl block (Tobin C. Harding)fa946796eb
Create a separate TxOut impl block (Tobin C. Harding) Pull request description: This one is pretty easy. Leaves the actual move of `TxOut` for later. ACKs for top commit: Kixunil: ACKb61adf7ca4
apoelstra: ACKb61adf7ca4
successfully ran local tests Tree-SHA512: 99c23f1cebdade0f4298bf46b6af66c02594f79096b82550a7d17d5a7d058afba3738c676deac2712cfec43798813a6e49ac53e39760677777c6910ccedf5bc8
This commit is contained in:
commit
02f0111c4e
|
@ -352,7 +352,11 @@ impl TxOut {
|
|||
/// This is used as a "null txout" in consensus signing code.
|
||||
pub const NULL: Self =
|
||||
TxOut { value: Amount::from_sat(0xffffffffffffffff), script_pubkey: ScriptBuf::new() };
|
||||
}
|
||||
|
||||
crate::internal_macros::define_extension_trait! {
|
||||
/// Extension functionality for the [`TxOut`] type.
|
||||
pub trait TxOutExt impl for TxOut {
|
||||
/// The weight of this output.
|
||||
///
|
||||
/// Keep in mind that when adding a [`TxOut`] to a [`Transaction`] the total weight of the
|
||||
|
@ -363,15 +367,16 @@ impl TxOut {
|
|||
///
|
||||
/// If output size * 4 overflows, this should never happen under normal conditions. Use
|
||||
/// `Weght::from_vb_checked(self.size().to_u64())` if you are concerned.
|
||||
pub fn weight(&self) -> Weight {
|
||||
fn weight(&self) -> Weight {
|
||||
// Size is equivalent to virtual size since all bytes of a TxOut are non-witness bytes.
|
||||
Weight::from_vb(self.size().to_u64()).expect("should never happen under normal conditions")
|
||||
Weight::from_vb(self.size().to_u64())
|
||||
.expect("should never happen under normal conditions")
|
||||
}
|
||||
|
||||
/// Returns the total number of bytes that this output contributes to a transaction.
|
||||
///
|
||||
/// There is no difference between base size vs total size for outputs.
|
||||
pub fn size(&self) -> usize { size_from_script_pubkey(&self.script_pubkey) }
|
||||
fn size(&self) -> usize { size_from_script_pubkey(&self.script_pubkey) }
|
||||
|
||||
/// Creates a `TxOut` with given script and the smallest possible `value` that is **not** dust
|
||||
/// per current Core policy.
|
||||
|
@ -382,7 +387,7 @@ impl TxOut {
|
|||
/// To use a custom value, use [`minimal_non_dust_custom`].
|
||||
///
|
||||
/// [`minimal_non_dust_custom`]: TxOut::minimal_non_dust_custom
|
||||
pub fn minimal_non_dust(script_pubkey: ScriptBuf) -> Self {
|
||||
fn minimal_non_dust(script_pubkey: ScriptBuf) -> Self {
|
||||
TxOut { value: script_pubkey.minimal_non_dust(), script_pubkey }
|
||||
}
|
||||
|
||||
|
@ -397,10 +402,11 @@ impl TxOut {
|
|||
/// To use the default Bitcoin Core value, use [`minimal_non_dust`].
|
||||
///
|
||||
/// [`minimal_non_dust`]: TxOut::minimal_non_dust
|
||||
pub fn minimal_non_dust_custom(script_pubkey: ScriptBuf, dust_relay_fee: FeeRate) -> Self {
|
||||
fn minimal_non_dust_custom(script_pubkey: ScriptBuf, dust_relay_fee: FeeRate) -> Self {
|
||||
TxOut { value: script_pubkey.minimal_non_dust_custom(dust_relay_fee), script_pubkey }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "arbitrary")]
|
||||
impl<'a> Arbitrary<'a> for TxOut {
|
||||
|
|
Loading…
Reference in New Issue