From 251e6a85da1610bd3b62d686d51212cfb08a6e2c Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 12 Jun 2025 10:25:55 +1000 Subject: [PATCH] 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. --- units/src/fee.rs | 14 -------------- units/src/weight.rs | 14 +++++++++++++- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/units/src/fee.rs b/units/src/fee.rs index 144ad0fd8..76aa55309 100644 --- a/units/src/fee.rs +++ b/units/src/fee.rs @@ -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 { - fee_rate.checked_mul_by_weight(self) - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/units/src/weight.rs b/units/src/weight.rs index 31da7274c..5bf700471 100644 --- a/units/src/weight.rs +++ b/units/src/weight.rs @@ -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 { + fee_rate.checked_mul_by_weight(self) + } } /// Alternative will display the unit.