Use _unchecked in amount const types

We are about to start enforcing the MAX_MONEY invariant. Doing so will
change constructors to return an error type.

In preparation use the `_unchecked` constructor for all the consts.

Internal change only, no logic changes.
This commit is contained in:
Tobin C. Harding 2025-02-28 09:41:10 +11:00
parent ef0af8d62e
commit e6f7b26d80
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
2 changed files with 11 additions and 11 deletions

View File

@ -50,17 +50,17 @@ pub struct SignedAmount(i64);
impl SignedAmount {
/// The zero amount.
pub const ZERO: Self = SignedAmount(0);
pub const ZERO: Self = SignedAmount::from_sat_unchecked(0);
/// Exactly one satoshi.
pub const ONE_SAT: Self = SignedAmount(1);
pub const ONE_SAT: Self = SignedAmount::from_sat_unchecked(1);
/// Exactly one bitcoin.
pub const ONE_BTC: Self = SignedAmount(100_000_000);
pub const ONE_BTC: Self = SignedAmount::from_sat_unchecked(100_000_000);
/// Exactly fifty bitcoin.
pub const FIFTY_BTC: Self = Self::from_sat_unchecked(50 * 100_000_000);
pub const FIFTY_BTC: Self = SignedAmount::from_sat_unchecked(50 * 100_000_000);
/// The maximum value allowed as an amount. Useful for sanity checking.
pub const MAX_MONEY: Self = SignedAmount(21_000_000 * 100_000_000);
pub const MAX_MONEY: Self = SignedAmount::from_sat_unchecked(21_000_000 * 100_000_000);
/// The minimum value of an amount.
pub const MIN: Self = SignedAmount(-21_000_000 * 100_000_000);
pub const MIN: Self = SignedAmount::from_sat_unchecked(-21_000_000 * 100_000_000);
/// The maximum value of an amount.
pub const MAX: Self = SignedAmount::MAX_MONEY;

View File

@ -42,15 +42,15 @@ pub struct Amount(u64);
impl Amount {
/// The zero amount.
pub const ZERO: Self = Amount(0);
pub const ZERO: Self = Amount::from_sat_unchecked(0);
/// Exactly one satoshi.
pub const ONE_SAT: Self = Amount(1);
pub const ONE_SAT: Self = Amount::from_sat_unchecked(1);
/// Exactly one bitcoin.
pub const ONE_BTC: Self = Self::from_int_btc_const(1);
pub const ONE_BTC: Self = Amount::from_sat_unchecked(100_000_000);
/// Exactly fifty bitcoin.
pub const FIFTY_BTC: Self = Self::from_sat_unchecked(50 * 100_000_000);
pub const FIFTY_BTC: Self = Amount::from_sat_unchecked(50 * 100_000_000);
/// The maximum value allowed as an amount. Useful for sanity checking.
pub const MAX_MONEY: Self = Self::from_int_btc_const(21_000_000);
pub const MAX_MONEY: Self = Amount::from_sat_unchecked(21_000_000 * 100_000_000);
/// The minimum value of an amount.
pub const MIN: Self = Amount::ZERO;
/// The maximum value of an amount.