Skip to content

Commit 2958521

Browse files
committed
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.
1 parent d0d7a15 commit 2958521

File tree

2 files changed

+3
-13
lines changed

2 files changed

+3
-13
lines changed

units/src/amount/signed.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ mod encapsulate {
5757
/// The minimum value of an amount.
5858
pub const MIN: Self = Self(-21_000_000 * 100_000_000);
5959

60-
/// Constructs a new [`SignedAmount`] with satoshi precision and the given number of satoshis.
61-
///
62-
/// Caller to guarantee that `satoshi` is within valid range.
63-
///
64-
/// See [`Self::MIN`] and [`Self::MAX`].
65-
pub const fn from_sat_unchecked(satoshi: i64) -> SignedAmount { SignedAmount(satoshi) }
66-
6760
/// Constructs a new [`SignedAmount`] with satoshi precision and the given number of satoshis.
6861
///
6962
/// Accepts an `i32` which is guaranteed to be in range for the type, but which can only

units/src/amount/unsigned.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ mod encapsulate {
5757
/// The minimum value of an amount.
5858
pub const MIN: Self = Self(0);
5959

60-
/// Constructs a new [`Amount`] with satoshi precision and the given number of satoshis.
61-
///
62-
/// Caller to guarantee that `satoshi` is within valid range. See [`Self::MAX`].
63-
pub const fn from_sat_unchecked(satoshi: u64) -> Amount { Self(satoshi) }
64-
6560
/// Constructs a new [`Amount`] with satoshi precision and the given number of satoshis.
6661
///
6762
/// Accepts an `u32` which is guaranteed to be in range for the type, but which can only
@@ -398,8 +393,10 @@ impl Amount {
398393

399394
/// Converts to a signed amount.
400395
#[rustfmt::skip] // Moves code comments to the wrong line.
396+
#[allow(clippy::missing_panics_doc)]
401397
pub fn to_signed(self) -> SignedAmount {
402-
SignedAmount::from_sat_unchecked(self.to_sat() as i64) // Cast ok, signed amount and amount share positive range.
398+
SignedAmount::from_sat(self.to_sat() as i64) // Cast ok, signed amount and amount share positive range.
399+
.expect("range of Amount is within range of SignedAmount")
403400
}
404401
}
405402

0 commit comments

Comments
 (0)