Repository: rust-bitcoin/rust-bitcoin (language: rust)

Issue:
Add fee-like functions
`FeeRate` * `Weigiht` = `Amount` 

Ensure there are functions on all thee types to calculate these. Keep the `checked_` nomenclature.

ref: https://github.com/rust-bitcoin/rust-bitcoin/pull/3736#issuecomment-2541469718


Discussion / hints:

Fix patch:
diff --git a/api/units/all-features.txt b/api/units/all-features.txt
index c08ae272b..5d5fdeab7 100644
--- a/api/units/all-features.txt
+++ b/api/units/all-features.txt
@@ -776,6 +776,7 @@ pub const fn bitcoin_units::locktime::relative::Time::value(self) -> u16
 pub const fn bitcoin_units::weight::Weight::checked_add(self, rhs: Self) -> core::option::Option<Self>
 pub const fn bitcoin_units::weight::Weight::checked_div(self, rhs: u64) -> core::option::Option<Self>
 pub const fn bitcoin_units::weight::Weight::checked_mul(self, rhs: u64) -> core::option::Option<Self>
+pub const fn bitcoin_units::weight::Weight::checked_mul_by_fee_rate(self, fee_rate: bitcoin_units::fee_rate::FeeRate) -> core::option::Option<bitcoin_units::Amount>
 pub const fn bitcoin_units::weight::Weight::checked_sub(self, rhs: Self) -> core::option::Option<Self>
 pub const fn bitcoin_units::weight::Weight::from_non_witness_data_size(non_witness_size: u64) -> Self
 pub const fn bitcoin_units::weight::Weight::from_vb(vb: u64) -> core::option::Option<Self>
diff --git a/api/units/alloc-only.txt b/api/units/alloc-only.txt
index 171de5f03..8aaeaeb7d 100644
--- a/api/units/alloc-only.txt
+++ b/api/units/alloc-only.txt
@@ -714,6 +714,7 @@ pub const fn bitcoin_units::locktime::relative::Time::value(self) -> u16
 pub const fn bitcoin_units::weight::Weight::checked_add(self, rhs: Self) -> core::option::Option<Self>
 pub const fn bitcoin_units::weight::Weight::checked_div(self, rhs: u64) -> core::option::Option<Self>
 pub const fn bitcoin_units::weight::Weight::checked_mul(self, rhs: u64) -> core::option::Option<Self>
+pub const fn bitcoin_units::weight::Weight::checked_mul_by_fee_rate(self, fee_rate: bitcoin_units::fee_rate::FeeRate) -> core::option::Option<bitcoin_units::Amount>
 pub const fn bitcoin_units::weight::Weight::checked_sub(self, rhs: Self) -> core::option::Option<Self>
 pub const fn bitcoin_units::weight::Weight::from_non_witness_data_size(non_witness_size: u64) -> Self
 pub const fn bitcoin_units::weight::Weight::from_vb(vb: u64) -> core::option::Option<Self>
diff --git a/api/units/no-features.txt b/api/units/no-features.txt
index 5526bb239..19a530501 100644
--- a/api/units/no-features.txt
+++ b/api/units/no-features.txt
@@ -696,6 +696,7 @@ pub const fn bitcoin_units::locktime::relative::Time::value(self) -> u16
 pub const fn bitcoin_units::weight::Weight::checked_add(self, rhs: Self) -> core::option::Option<Self>
 pub const fn bitcoin_units::weight::Weight::checked_div(self, rhs: u64) -> core::option::Option<Self>
 pub const fn bitcoin_units::weight::Weight::checked_mul(self, rhs: u64) -> core::option::Option<Self>
+pub const fn bitcoin_units::weight::Weight::checked_mul_by_fee_rate(self, fee_rate: bitcoin_units::fee_rate::FeeRate) -> core::option::Option<bitcoin_units::Amount>
 pub const fn bitcoin_units::weight::Weight::checked_sub(self, rhs: Self) -> core::option::Option<Self>
 pub const fn bitcoin_units::weight::Weight::from_non_witness_data_size(non_witness_size: u64) -> Self
 pub const fn bitcoin_units::weight::Weight::from_vb(vb: u64) -> core::option::Option<Self>
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<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::*;


Test patch: