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.
This commit is contained in:
Tobin C. Harding 2024-10-18 14:09:40 +11:00
parent 456bbf11d1
commit 265589d93d
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
1 changed files with 8 additions and 7 deletions

View File

@ -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. /// Bitcoin transaction input.
/// ///
/// It contains the location of the previous transaction's output, /// It contains the location of the previous transaction's output,
@ -121,12 +128,6 @@ impl TxIn {
witness: Witness::new(), 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 /// Returns true if this input enables the [`absolute::LockTime`] (aka `nLockTime`) of its
/// [`Transaction`]. /// [`Transaction`].
/// ///
@ -955,7 +956,7 @@ pub fn effective_value(
satisfaction_weight: Weight, satisfaction_weight: Weight,
value: Amount, value: Amount,
) -> Option<SignedAmount> { ) -> Option<SignedAmount> {
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()?; let signed_input_fee = fee_rate.checked_mul_by_weight(weight)?.to_signed().ok()?;
value.to_signed().ok()?.checked_sub(signed_input_fee) value.to_signed().ok()?.checked_sub(signed_input_fee)
} }