Merge rust-bitcoin/rust-bitcoin#3723: Use Self in amount consts

55092aab47 Use Self in amount consts (Tobin C. Harding)

Pull request description:

  Currently the consts in the `amount` modules repeat the type. For `Amount` this isn't a big deal but for `SignedAmount` its quite noisy.

  Use `Self` as the type in const declarations inside `Amount` and `SignedAmount`.

  Internal change, no logic changes.

ACKs for top commit:
  apoelstra:
    ACK 55092aab47051e740c1ee43de73e367a2f9299a3; successfully ran local tests

Tree-SHA512: 8220541f3bac85f0a40382e9545500709dac6d96496cfae76c0ff41afd937b6452e3fa12390b38f80e586a2b52baa384c580c5fe3e8ac9e80ea394b3b3ee26db
This commit is contained in:
merge-script 2024-12-15 14:44:42 +00:00
commit eeb4089b3f
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 12 additions and 12 deletions

View File

@ -50,17 +50,17 @@ pub struct SignedAmount(i64);
impl SignedAmount { impl SignedAmount {
/// The zero amount. /// The zero amount.
pub const ZERO: SignedAmount = SignedAmount(0); pub const ZERO: Self = SignedAmount(0);
/// Exactly one satoshi. /// Exactly one satoshi.
pub const ONE_SAT: SignedAmount = SignedAmount(1); pub const ONE_SAT: Self = SignedAmount(1);
/// Exactly one bitcoin. /// Exactly one bitcoin.
pub const ONE_BTC: SignedAmount = SignedAmount(100_000_000); pub const ONE_BTC: Self = SignedAmount(100_000_000);
/// The maximum value allowed as an amount. Useful for sanity checking. /// The maximum value allowed as an amount. Useful for sanity checking.
pub const MAX_MONEY: SignedAmount = SignedAmount(21_000_000 * 100_000_000); pub const MAX_MONEY: Self = SignedAmount(21_000_000 * 100_000_000);
/// The minimum value of an amount. /// The minimum value of an amount.
pub const MIN: SignedAmount = SignedAmount(-21_000_000 * 100_000_000); pub const MIN: Self = SignedAmount(-21_000_000 * 100_000_000);
/// The maximum value of an amount. /// The maximum value of an amount.
pub const MAX: SignedAmount = SignedAmount::MAX_MONEY; pub const MAX: Self = SignedAmount::MAX_MONEY;
/// Constructs a new [`SignedAmount`] with satoshi precision and the given number of satoshis. /// Constructs a new [`SignedAmount`] with satoshi precision and the given number of satoshis.
pub const fn from_sat(satoshi: i64) -> SignedAmount { SignedAmount(satoshi) } pub const fn from_sat(satoshi: i64) -> SignedAmount { SignedAmount(satoshi) }

View File

@ -55,17 +55,17 @@ pub struct Amount(u64);
impl Amount { impl Amount {
/// The zero amount. /// The zero amount.
pub const ZERO: Amount = Amount(0); pub const ZERO: Self = Amount(0);
/// Exactly one satoshi. /// Exactly one satoshi.
pub const ONE_SAT: Amount = Amount(1); pub const ONE_SAT: Self = Amount(1);
/// Exactly one bitcoin. /// Exactly one bitcoin.
pub const ONE_BTC: Amount = Self::from_int_btc_const(1); pub const ONE_BTC: Self = Self::from_int_btc_const(1);
/// The maximum value allowed as an amount. Useful for sanity checking. /// The maximum value allowed as an amount. Useful for sanity checking.
pub const MAX_MONEY: Amount = Self::from_int_btc_const(21_000_000); pub const MAX_MONEY: Self = Self::from_int_btc_const(21_000_000);
/// The minimum value of an amount. /// The minimum value of an amount.
pub const MIN: Amount = Amount::ZERO; pub const MIN: Self = Amount::ZERO;
/// The maximum value of an amount. /// The maximum value of an amount.
pub const MAX: Amount = Amount::MAX_MONEY; pub const MAX: Self = Amount::MAX_MONEY;
/// The number of bytes that an amount contributes to the size of a transaction. /// The number of bytes that an amount contributes to the size of a transaction.
pub const SIZE: usize = 8; // Serialized length of a u64. pub const SIZE: usize = 8; // Serialized length of a u64.