Inline checked mul function back into weight module

A while back we move all the 'fee' stuff into a separate module
because I thought it would help with clarity - I was wrong.

Move the checked mul function back into the `weight` module on the main
`Weight` impl block.

Internal change only - code move.
This commit is contained in:
Tobin C. Harding 2025-06-12 10:25:55 +10:00
parent a8610a937b
commit 251e6a85da
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 13 additions and 15 deletions

View File

@ -181,20 +181,6 @@ crate::internal_macros::impl_op_for_references! {
}
}
impl Weight {
/// Checked fee rate multiplication.
///
/// Computes the absolute fee amount for a given [`FeeRate`] at this weight. When the resulting
/// fee is a non-integer amount, the amount is rounded up, ensuring that the transaction fee is
/// enough instead of falling short if rounded down.
///
/// Returns [`None`] if overflow occurred.
#[must_use]
pub const fn checked_mul_by_fee_rate(self, fee_rate: FeeRate) -> Option<Amount> {
fee_rate.checked_mul_by_weight(self)
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -10,7 +10,7 @@ use arbitrary::{Arbitrary, Unstructured};
#[cfg(feature = "serde")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::CheckedSum;
use crate::{Amount, CheckedSum, FeeRate};
/// The factor that non-witness serialization data is multiplied by during weight calculation.
pub const WITNESS_SCALE_FACTOR: usize = 4;
@ -162,6 +162,18 @@ impl Weight {
None => None,
}
}
/// Checked fee rate multiplication.
///
/// Computes the absolute fee amount for a given [`FeeRate`] at this weight. When the resulting
/// fee is a non-integer amount, the amount is rounded up, ensuring that the transaction fee is
/// enough instead of falling short if rounded down.
///
/// Returns [`None`] if overflow occurred.
#[must_use]
pub const fn checked_mul_by_fee_rate(self, fee_rate: FeeRate) -> Option<Amount> {
fee_rate.checked_mul_by_weight(self)
}
}
/// Alternative will display the unit.