From 265589d93d1a6c144bf9f429cb94c0ee763f0750 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 18 Oct 2024 14:09:40 +1100 Subject: [PATCH] Make TxIn::BASE_WEIGHT a file level const In preparation for moving the `TxIn` over to `primitives` make the private `TxIn::BASE_WEIGHT` associated const into a file-scoped constant because the other alternative is to make it public. --- bitcoin/src/blockdata/transaction.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index e593a987e..faf94e1cd 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -82,6 +82,13 @@ crate::internal_macros::define_extension_trait! { } } +/// Returns the input base weight. +/// +/// Base weight excludes the witness and script. +// We need to use this const here but do not want to make it public in `primitives::TxIn`. +const TX_IN_BASE_WEIGHT: Weight = + Weight::from_vb_unwrap(OutPoint::SIZE as u64 + Sequence::SIZE as u64); + /// Bitcoin transaction input. /// /// It contains the location of the previous transaction's output, @@ -121,12 +128,6 @@ impl TxIn { witness: Witness::new(), }; - /// Returns the input base weight. - /// - /// Base weight excludes the witness and script. - const BASE_WEIGHT: Weight = - Weight::from_vb_unwrap(OutPoint::SIZE as u64 + Sequence::SIZE as u64); - /// Returns true if this input enables the [`absolute::LockTime`] (aka `nLockTime`) of its /// [`Transaction`]. /// @@ -955,7 +956,7 @@ pub fn effective_value( satisfaction_weight: Weight, value: Amount, ) -> Option { - let weight = satisfaction_weight.checked_add(TxIn::BASE_WEIGHT)?; + let weight = satisfaction_weight.checked_add(TX_IN_BASE_WEIGHT)?; let signed_input_fee = fee_rate.checked_mul_by_weight(weight)?.to_signed().ok()?; value.to_signed().ok()?.checked_sub(signed_input_fee) }