From 2958521117e6ec3db98ec42c490b3dfea60f7ab3 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Tue, 18 Mar 2025 14:34:44 +0000 Subject: [PATCH] amount: remove from_sat_unchecked Turns out we don't even need this. It is only used in one place now and we can just stick an .expect there. --- units/src/amount/signed.rs | 7 ------- units/src/amount/unsigned.rs | 9 +++------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/units/src/amount/signed.rs b/units/src/amount/signed.rs index 069eceee0..cc16fb8ee 100644 --- a/units/src/amount/signed.rs +++ b/units/src/amount/signed.rs @@ -57,13 +57,6 @@ mod encapsulate { /// The minimum value of an amount. pub const MIN: Self = Self(-21_000_000 * 100_000_000); - /// Constructs a new [`SignedAmount`] with satoshi precision and the given number of satoshis. - /// - /// Caller to guarantee that `satoshi` is within valid range. - /// - /// See [`Self::MIN`] and [`Self::MAX`]. - pub const fn from_sat_unchecked(satoshi: i64) -> SignedAmount { SignedAmount(satoshi) } - /// Constructs a new [`SignedAmount`] with satoshi precision and the given number of satoshis. /// /// Accepts an `i32` which is guaranteed to be in range for the type, but which can only diff --git a/units/src/amount/unsigned.rs b/units/src/amount/unsigned.rs index d82c3f881..1ff3637b6 100644 --- a/units/src/amount/unsigned.rs +++ b/units/src/amount/unsigned.rs @@ -57,11 +57,6 @@ mod encapsulate { /// The minimum value of an amount. pub const MIN: Self = Self(0); - /// Constructs a new [`Amount`] with satoshi precision and the given number of satoshis. - /// - /// Caller to guarantee that `satoshi` is within valid range. See [`Self::MAX`]. - pub const fn from_sat_unchecked(satoshi: u64) -> Amount { Self(satoshi) } - /// Constructs a new [`Amount`] with satoshi precision and the given number of satoshis. /// /// Accepts an `u32` which is guaranteed to be in range for the type, but which can only @@ -398,8 +393,10 @@ impl Amount { /// Converts to a signed amount. #[rustfmt::skip] // Moves code comments to the wrong line. + #[allow(clippy::missing_panics_doc)] pub fn to_signed(self) -> SignedAmount { - SignedAmount::from_sat_unchecked(self.to_sat() as i64) // Cast ok, signed amount and amount share positive range. + SignedAmount::from_sat(self.to_sat() as i64) // Cast ok, signed amount and amount share positive range. + .expect("range of Amount is within range of SignedAmount") } }