diff --git a/units/src/fee.rs b/units/src/fee.rs index 833399279..f53a15c89 100644 --- a/units/src/fee.rs +++ b/units/src/fee.rs @@ -191,6 +191,21 @@ impl ops::Div for Amount { fn div(self, rhs: FeeRate) -> Self::Output { self.checked_div_by_fee_rate_floor(rhs).unwrap() } } +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. + /// + /// [`None`] is returned if an 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::*;