Add Weight::checked_mul_by_fee_rate method
Mirror FeeRate::checked_mul_by_weight functionality by adding a symmetrical method to Weight. This allows users to calculate fees starting from either Weight or FeeRate with consistent behavior.
This commit is contained in:
parent
98db7bca74
commit
134c146748
|
@ -191,6 +191,21 @@ impl ops::Div<FeeRate> 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<Amount> {
|
||||
fee_rate.checked_mul_by_weight(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in New Issue