From 5eb5941215f7aeff2de513d098de267d3968e367 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 17 Jan 2025 10:08:09 +1100 Subject: [PATCH] Add FIFTY_BTC const to the amount types 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`. --- bitcoin/examples/taproot-psbt.rs | 6 +++--- bitcoin/src/blockdata/constants.rs | 2 +- units/src/amount/signed.rs | 2 ++ units/src/amount/unsigned.rs | 2 ++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bitcoin/examples/taproot-psbt.rs b/bitcoin/examples/taproot-psbt.rs index 16b065099..d75b4e14f 100644 --- a/bitcoin/examples/taproot-psbt.rs +++ b/bitcoin/examples/taproot-psbt.rs @@ -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, }; @@ -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, }; @@ -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, }; diff --git a/bitcoin/src/blockdata/constants.rs b/bitcoin/src/blockdata/constants.rs index dd45b1c88..e1f15030c 100644 --- a/bitcoin/src/blockdata/constants.rs +++ b/bitcoin/src/blockdata/constants.rs @@ -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, }); diff --git a/units/src/amount/signed.rs b/units/src/amount/signed.rs index ada79d170..82a07fa05 100644 --- a/units/src/amount/signed.rs +++ b/units/src/amount/signed.rs @@ -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. diff --git a/units/src/amount/unsigned.rs b/units/src/amount/unsigned.rs index 443b1fcd8..d3c494921 100644 --- a/units/src/amount/unsigned.rs +++ b/units/src/amount/unsigned.rs @@ -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.