Skip to content

Commit

Permalink
Remove deprecated amount methods
Browse files Browse the repository at this point in the history
When we enforce the MAX_MONEY invariant these functions would require
the function signature changing - might as well just delete them.
  • Loading branch information
tcharding authored and apoelstra committed Mar 8, 2025
1 parent d8bae68 commit 26d79a4
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 61 deletions.
26 changes: 0 additions & 26 deletions units/src/amount/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,32 +402,6 @@ impl SignedAmount {
}
}

/// Unchecked addition.
///
/// Computes `self + rhs`.
///
/// # Panics
///
/// On overflow, panics in debug mode, wraps in release mode.
#[must_use]
#[deprecated(since = "TBD", note = "consider converting to u64 using `to_sat`")]
pub fn unchecked_add(self, rhs: SignedAmount) -> SignedAmount {
Self::from_sat(self.to_sat() + rhs.to_sat())
}

/// Unchecked subtraction.
///
/// Computes `self - rhs`.
///
/// # Panics
///
/// On overflow, panics in debug mode, wraps in release mode.
#[must_use]
#[deprecated(since = "TBD", note = "consider converting to u64 using `to_sat`")]
pub fn unchecked_sub(self, rhs: SignedAmount) -> SignedAmount {
Self::from_sat(self.to_sat() - rhs.to_sat())
}

/// Subtraction that doesn't allow negative [`SignedAmount`]s.
///
/// Returns [`None`] if either `self`, `rhs` or the result is strictly negative.
Expand Down
9 changes: 0 additions & 9 deletions units/src/amount/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,6 @@ fn checked_arithmetic() {
assert_eq!(ssat(-6).checked_div(2), Some(ssat(-3)));
}

#[test]
#[allow(deprecated_in_future)]
fn unchecked_arithmetic() {
assert_eq!(ssat(10).unchecked_add(ssat(20)), ssat(30));
assert_eq!(ssat(50).unchecked_sub(ssat(10)), ssat(40));
assert_eq!(sat(5).unchecked_add(sat(7)), sat(12));
assert_eq!(sat(10).unchecked_sub(sat(7)), sat(3));
}

#[test]
fn positive_sub() {
assert_eq!(ssat(10).positive_sub(ssat(7)).unwrap(), ssat(3));
Expand Down
26 changes: 0 additions & 26 deletions units/src/amount/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,32 +361,6 @@ impl Amount {
}
}

/// Unchecked addition.
///
/// Computes `self + rhs`.
///
/// # Panics
///
/// On overflow, panics in debug mode, wraps in release mode.
#[must_use]
#[deprecated(since = "TBD", note = "consider converting to u64 using `to_sat`")]
pub fn unchecked_add(self, rhs: Amount) -> Amount {
Self::from_sat(self.to_sat() + rhs.to_sat())
}

/// Unchecked subtraction.
///
/// Computes `self - rhs`.
///
/// # Panics
///
/// On overflow, panics in debug mode, wraps in release mode.
#[must_use]
#[deprecated(since = "TBD", note = "consider converting to u64 using `to_sat`")]
pub fn unchecked_sub(self, rhs: Amount) -> Amount {
Self::from_sat(self.to_sat() - rhs.to_sat())
}

/// Converts to a signed amount.
#[rustfmt::skip] // Moves code comments to the wrong line.
pub fn to_signed(self) -> SignedAmount {
Expand Down

0 comments on commit 26d79a4

Please sign in to comment.