amount: rename `from_int_btc_const` unctions to hungarian ones

We have `from_int_btc_const` on both `Amount` and `SignedAmount` because
the "real" `from_int_btc` is generic over the integer type it accepts,
which means that it cannot be a constfn. But we do want a constfn.

However, just because `from_int_btc_const` exists for the sake of
constfn doesn't mean that that's what it *is*. So rename these methods
to reflect what they *are*.
This commit is contained in:
Andrew Poelstra 2025-03-18 13:24:54 +00:00
parent 2ec1c2a044
commit 82d9d1aeea
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 11 additions and 9 deletions

View File

@ -77,9 +77,9 @@ impl SignedAmount {
/// Exactly one satoshi.
pub const ONE_SAT: Self = SignedAmount::from_sat_unchecked(1);
/// Exactly one bitcoin.
pub const ONE_BTC: Self = SignedAmount::from_int_btc_const(1);
pub const ONE_BTC: Self = SignedAmount::from_btc_i16(1);
/// Exactly fifty bitcoin.
pub const FIFTY_BTC: Self = SignedAmount::from_int_btc_const(50);
pub const FIFTY_BTC: Self = SignedAmount::from_btc_i16(50);
/// The maximum value allowed as an amount. Useful for sanity checking.
pub const MAX_MONEY: Self = SignedAmount::from_sat_unchecked(21_000_000 * 100_000_000);
/// The minimum value of an amount.
@ -136,13 +136,13 @@ impl SignedAmount {
/// Converts from a value expressing a whole number of bitcoin to a [`SignedAmount`].
#[allow(clippy::missing_panics_doc)]
pub fn from_int_btc<T: Into<i16>>(whole_bitcoin: T) -> SignedAmount {
SignedAmount::from_int_btc_const(whole_bitcoin.into())
SignedAmount::from_btc_i16(whole_bitcoin.into())
}
/// Converts from a value expressing a whole number of bitcoin to a [`SignedAmount`]
/// in const context.
#[allow(clippy::missing_panics_doc)]
pub const fn from_int_btc_const(whole_bitcoin: i16) -> SignedAmount {
pub const fn from_btc_i16(whole_bitcoin: i16) -> SignedAmount {
let btc = whole_bitcoin as i64; // Can't call `into` in const context.
let sats = btc * 100_000_000;

View File

@ -102,8 +102,10 @@ fn from_str_zero_without_denomination() {
#[test]
fn from_int_btc() {
let amt = Amount::from_int_btc_const(2);
let amt = Amount::from_btc_u16(2);
assert_eq!(sat(200_000_000), amt);
let amt = SignedAmount::from_btc_i16(-2);
assert_eq!(ssat(-200_000_000), amt);
}
#[test]

View File

@ -75,9 +75,9 @@ impl Amount {
/// Exactly one satoshi.
pub const ONE_SAT: Self = Amount::from_sat_unchecked(1);
/// Exactly one bitcoin.
pub const ONE_BTC: Self = Amount::from_int_btc_const(1);
pub const ONE_BTC: Self = Amount::from_btc_u16(1);
/// Exactly fifty bitcoin.
pub const FIFTY_BTC: Self = Amount::from_int_btc_const(50);
pub const FIFTY_BTC: Self = Amount::from_btc_u16(50);
/// The maximum value allowed as an amount. Useful for sanity checking.
pub const MAX_MONEY: Self = Amount::from_sat_unchecked(21_000_000 * 100_000_000);
/// The minimum value of an amount.
@ -134,13 +134,13 @@ impl Amount {
/// Converts from a value expressing a whole number of bitcoin to an [`Amount`].
#[allow(clippy::missing_panics_doc)]
pub fn from_int_btc<T: Into<u16>>(whole_bitcoin: T) -> Amount {
Amount::from_int_btc_const(whole_bitcoin.into())
Amount::from_btc_u16(whole_bitcoin.into())
}
/// Converts from a value expressing a whole number of bitcoin to an [`Amount`]
/// in const context.
#[allow(clippy::missing_panics_doc)]
pub const fn from_int_btc_const(whole_bitcoin: u16) -> Amount {
pub const fn from_btc_u16(whole_bitcoin: u16) -> Amount {
let btc = whole_bitcoin as u64; // Can't call `into` in const context.
let sats = btc * 100_000_000;