Skip to content

Commit

Permalink
Merge rust-bitcoin#3915: Add FIFTY_BTC const to the amount types
Browse files Browse the repository at this point in the history
e002823 api: Run just check-api (Tobin C. Harding)
5eb5941 Add FIFTY_BTC const to the amount types (Tobin C. Harding)

Pull request description:

  The mining reward for the first epoc is 50 bitcoin. For mainnet this is old news but for regtest it is still relevant.

  Add and use a new const `FIFTY_BTC` to the `Amount` type. To keep the amount types uniform also add it to the `SignedAmount`.

ACKs for top commit:
  storopoli:
    ACK e002823
  jamillambert:
    ACK e002823
  apoelstra:
    ACK e002823; successfully ran local tests

Tree-SHA512: 623ed8b1f5fe8dd95309179308fea83d68be4349becf6305769b0378cc9032961df2c062dc2bf702fec5e2394e8abb7360d2be6f19b6cf505db8769a5ae39e16
  • Loading branch information
apoelstra committed Jan 20, 2025
2 parents 3985333 + e002823 commit 05c28cf
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions api/units/all-features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,15 @@ pub bitcoin_units::amount::Denomination::MilliBitcoin
pub bitcoin_units::amount::Denomination::Satoshi
pub bitcoin_units::amount::ParseDenominationError::PossiblyConfusing(bitcoin_units::amount::PossiblyConfusingDenominationError)
pub bitcoin_units::amount::ParseDenominationError::Unknown(bitcoin_units::amount::UnknownDenominationError)
pub const bitcoin_units::Amount::FIFTY_BTC: Self
pub const bitcoin_units::Amount::MAX: Self
pub const bitcoin_units::Amount::MAX_MONEY: Self
pub const bitcoin_units::Amount::MIN: Self
pub const bitcoin_units::Amount::ONE_BTC: Self
pub const bitcoin_units::Amount::ONE_SAT: Self
pub const bitcoin_units::Amount::SIZE: usize
pub const bitcoin_units::Amount::ZERO: Self
pub const bitcoin_units::SignedAmount::FIFTY_BTC: Self
pub const bitcoin_units::SignedAmount::MAX: Self
pub const bitcoin_units::SignedAmount::MAX_MONEY: Self
pub const bitcoin_units::SignedAmount::MIN: Self
Expand Down
2 changes: 2 additions & 0 deletions api/units/alloc-only.txt
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,15 @@ pub bitcoin_units::amount::Denomination::MilliBitcoin
pub bitcoin_units::amount::Denomination::Satoshi
pub bitcoin_units::amount::ParseDenominationError::PossiblyConfusing(bitcoin_units::amount::PossiblyConfusingDenominationError)
pub bitcoin_units::amount::ParseDenominationError::Unknown(bitcoin_units::amount::UnknownDenominationError)
pub const bitcoin_units::Amount::FIFTY_BTC: Self
pub const bitcoin_units::Amount::MAX: Self
pub const bitcoin_units::Amount::MAX_MONEY: Self
pub const bitcoin_units::Amount::MIN: Self
pub const bitcoin_units::Amount::ONE_BTC: Self
pub const bitcoin_units::Amount::ONE_SAT: Self
pub const bitcoin_units::Amount::SIZE: usize
pub const bitcoin_units::Amount::ZERO: Self
pub const bitcoin_units::SignedAmount::FIFTY_BTC: Self
pub const bitcoin_units::SignedAmount::MAX: Self
pub const bitcoin_units::SignedAmount::MAX_MONEY: Self
pub const bitcoin_units::SignedAmount::MIN: Self
Expand Down
2 changes: 2 additions & 0 deletions api/units/no-features.txt
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,15 @@ pub bitcoin_units::amount::Denomination::MilliBitcoin
pub bitcoin_units::amount::Denomination::Satoshi
pub bitcoin_units::amount::ParseDenominationError::PossiblyConfusing(bitcoin_units::amount::PossiblyConfusingDenominationError)
pub bitcoin_units::amount::ParseDenominationError::Unknown(bitcoin_units::amount::UnknownDenominationError)
pub const bitcoin_units::Amount::FIFTY_BTC: Self
pub const bitcoin_units::Amount::MAX: Self
pub const bitcoin_units::Amount::MAX_MONEY: Self
pub const bitcoin_units::Amount::MIN: Self
pub const bitcoin_units::Amount::ONE_BTC: Self
pub const bitcoin_units::Amount::ONE_SAT: Self
pub const bitcoin_units::Amount::SIZE: usize
pub const bitcoin_units::Amount::ZERO: Self
pub const bitcoin_units::SignedAmount::FIFTY_BTC: Self
pub const bitcoin_units::SignedAmount::MAX: Self
pub const bitcoin_units::SignedAmount::MAX_MONEY: Self
pub const bitcoin_units::SignedAmount::MIN: Self
Expand Down
6 changes: 3 additions & 3 deletions bitcoin/examples/taproot-psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const UTXO_1: P2trUtxo = P2trUtxo {
script_pubkey: UTXO_SCRIPT_PUBKEY,
pubkey: UTXO_PUBKEY,
master_fingerprint: UTXO_MASTER_FINGERPRINT,
amount_in_sats: Amount::from_int_btc_const(50),
amount_in_sats: Amount::FIFTY_BTC,
derivation_path: BIP86_DERIVATION_PATH,
};

Expand All @@ -60,7 +60,7 @@ const UTXO_2: P2trUtxo = P2trUtxo {
script_pubkey: UTXO_SCRIPT_PUBKEY,
pubkey: UTXO_PUBKEY,
master_fingerprint: UTXO_MASTER_FINGERPRINT,
amount_in_sats: Amount::from_int_btc_const(50),
amount_in_sats: Amount::FIFTY_BTC,
derivation_path: BIP86_DERIVATION_PATH,
};

Expand All @@ -71,7 +71,7 @@ const UTXO_3: P2trUtxo = P2trUtxo {
script_pubkey: UTXO_SCRIPT_PUBKEY,
pubkey: UTXO_PUBKEY,
master_fingerprint: UTXO_MASTER_FINGERPRINT,
amount_in_sats: Amount::from_int_btc_const(50),
amount_in_sats: Amount::FIFTY_BTC,
derivation_path: BIP86_DERIVATION_PATH,
};

Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/blockdata/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn bitcoin_genesis_tx(params: &Params) -> Transaction {
});

ret.output.push(TxOut {
value: Amount::from_sat_unchecked(50 * 100_000_000),
value: Amount::FIFTY_BTC,
script_pubkey: out_script,
});

Expand Down
2 changes: 2 additions & 0 deletions units/src/amount/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ impl SignedAmount {
pub const ONE_SAT: Self = SignedAmount(1);
/// Exactly one bitcoin.
pub const ONE_BTC: Self = SignedAmount(100_000_000);
/// Exactly fifty bitcoin.
pub const FIFTY_BTC: Self = Self::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);
/// The minimum value of an amount.
Expand Down
2 changes: 2 additions & 0 deletions units/src/amount/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ impl Amount {
pub const ONE_SAT: Self = Amount(1);
/// Exactly one bitcoin.
pub const ONE_BTC: Self = Self::from_int_btc_const(1);
/// Exactly fifty bitcoin.
pub const FIFTY_BTC: Self = Self::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);
/// The minimum value of an amount.
Expand Down

0 comments on commit 05c28cf

Please sign in to comment.