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.
This commit is contained in:
Andrew Poelstra 2025-03-18 14:34:44 +00:00
parent d0d7a15604
commit 2958521117
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 3 additions and 13 deletions

View File

@ -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

View File

@ -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")
}
}