Skip to content

Commit 251e6a8

Browse files
committed
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.
1 parent a8610a9 commit 251e6a8

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

units/src/fee.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,6 @@ crate::internal_macros::impl_op_for_references! {
181181
}
182182
}
183183

184-
impl Weight {
185-
/// Checked fee rate multiplication.
186-
///
187-
/// Computes the absolute fee amount for a given [`FeeRate`] at this weight. When the resulting
188-
/// fee is a non-integer amount, the amount is rounded up, ensuring that the transaction fee is
189-
/// enough instead of falling short if rounded down.
190-
///
191-
/// Returns [`None`] if overflow occurred.
192-
#[must_use]
193-
pub const fn checked_mul_by_fee_rate(self, fee_rate: FeeRate) -> Option<Amount> {
194-
fee_rate.checked_mul_by_weight(self)
195-
}
196-
}
197-
198184
#[cfg(test)]
199185
mod tests {
200186
use super::*;

units/src/weight.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use arbitrary::{Arbitrary, Unstructured};
1010
#[cfg(feature = "serde")]
1111
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1212

13-
use crate::CheckedSum;
13+
use crate::{Amount, CheckedSum, FeeRate};
1414

1515
/// The factor that non-witness serialization data is multiplied by during weight calculation.
1616
pub const WITNESS_SCALE_FACTOR: usize = 4;
@@ -162,6 +162,18 @@ impl Weight {
162162
None => None,
163163
}
164164
}
165+
166+
/// Checked fee rate multiplication.
167+
///
168+
/// Computes the absolute fee amount for a given [`FeeRate`] at this weight. When the resulting
169+
/// fee is a non-integer amount, the amount is rounded up, ensuring that the transaction fee is
170+
/// enough instead of falling short if rounded down.
171+
///
172+
/// Returns [`None`] if overflow occurred.
173+
#[must_use]
174+
pub const fn checked_mul_by_fee_rate(self, fee_rate: FeeRate) -> Option<Amount> {
175+
fee_rate.checked_mul_by_weight(self)
176+
}
165177
}
166178

167179
/// Alternative will display the unit.

0 commit comments

Comments
 (0)