From 1bd1e89458fe5ddca8c5c199bd3859a09640c636 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Wed, 21 May 2025 11:23:48 +1000 Subject: [PATCH] Re-introduce FeeRate encapsulate module Now we have the `fee_rate` module clened up re-introduce the `encapsulate` module using MvB. --- units/src/fee_rate/mod.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/units/src/fee_rate/mod.rs b/units/src/fee_rate/mod.rs index 87e89c50b..ceaf239f4 100644 --- a/units/src/fee_rate/mod.rs +++ b/units/src/fee_rate/mod.rs @@ -11,12 +11,24 @@ use core::ops; #[cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Unstructured}; -/// Fee rate. -/// -/// This is an integer newtype representing fee rate in `sat/kwu`. It provides protection -/// against mixing up the types as well as basic formatting features. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] -pub struct FeeRate(u64); +mod encapsulate { + /// Fee rate. + /// + /// This is an integer newtype representing fee rate. It provides protection + /// against mixing up the types, conversion functions, and basic formatting. + #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] + pub struct FeeRate(u64); + + impl FeeRate { + /// Constructs a new [`FeeRate`] from satoshis per 1,000,000 virtual bytes. + pub(crate) const fn from_sat_per_mvb(sat_mvb: u64) -> Self { Self(sat_mvb) } + + /// Converts to sat/MvB. + pub(crate) const fn to_sat_per_mvb(self) -> u64 { self.0 } + } +} +#[doc(inline)] +pub use encapsulate::FeeRate; impl FeeRate { /// 0 sat/kwu. @@ -40,9 +52,6 @@ impl FeeRate { /// Fee rate used to compute dust amount. pub const DUST: FeeRate = FeeRate::from_sat_per_vb_u32(3); - /// Constructs a new [`FeeRate`] from satoshis per 1,000,000 virtual bytes. - pub(crate) const fn from_sat_per_mvb(sat_mvb: u64) -> Self { Self(sat_mvb) } - /// Constructs a new [`FeeRate`] from satoshis per 1000 weight units. pub const fn from_sat_per_kwu(sat_kwu: u64) -> Option { // No `map()` in const context. @@ -80,9 +89,6 @@ impl FeeRate { } } - /// Converts to sat/MvB. - pub(crate) const fn to_sat_per_mvb(self) -> u64 { self.0 } - /// Converts to sat/kwu rounding down. pub const fn to_sat_per_kwu_floor(self) -> u64 { self.to_sat_per_mvb() / 4_000 }