Merge rust-bitcoin/rust-bitcoin#2396: Add consts to Params for individual networks

3a56ecc677 Add consts to Params for individual networks (Tobin C. Harding)

Pull request description:

  Add consts to the `Params` type for the individual networks.

ACKs for top commit:
  apoelstra:
    ACK 3a56ecc677
  Kixunil:
    ACK 3a56ecc677
  sanket1729:
    ACK 3a56ecc677

Tree-SHA512: 0d265a14dd6a591a267da5381d3dcfd0d313f950dec4922f96d25349047d0c8a366c41dcdc1fc523fe4b178ec6a00b717bda25286625e222194f345cee5e7a97
This commit is contained in:
Andrew Poelstra 2024-03-09 13:04:06 +00:00
commit f69417f8bc
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 73 additions and 57 deletions

View File

@ -49,10 +49,11 @@ pub struct Params {
}
impl Params {
/// Creates parameters set for the given network.
pub const fn new(network: Network) -> Self {
match network {
Network::Bitcoin => Params {
/// The mainnet parameters (alias for `Params::MAINNET`).
pub const BITCOIN: Params = Params::MAINNET;
/// The mainnet parameters.
pub const MAINNET: Params = Params {
network: Network::Bitcoin,
bip16_time: 1333238400, // Apr 1 2012
bip34_height: 227931, // 000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8
@ -65,8 +66,10 @@ impl Params {
pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks.
allow_min_difficulty_blocks: false,
no_pow_retargeting: false,
},
Network::Testnet => Params {
};
/// The testnet parameters.
pub const TESTNET: Params = Params {
network: Network::Testnet,
bip16_time: 1333238400, // Apr 1 2012
bip34_height: 21111, // 0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8
@ -79,8 +82,10 @@ impl Params {
pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks.
allow_min_difficulty_blocks: true,
no_pow_retargeting: false,
},
Network::Signet => Params {
};
/// The signet parameters.
pub const SIGNET: Params = Params {
network: Network::Signet,
bip16_time: 1333238400, // Apr 1 2012
bip34_height: 1,
@ -93,8 +98,10 @@ impl Params {
pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks.
allow_min_difficulty_blocks: false,
no_pow_retargeting: false,
},
Network::Regtest => Params {
};
/// The regtest parameters.
pub const REGTEST: Params = Params {
network: Network::Regtest,
bip16_time: 1333238400, // Apr 1 2012
bip34_height: 100000000, // not activated on regtest
@ -107,7 +114,15 @@ impl Params {
pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks.
allow_min_difficulty_blocks: true,
no_pow_retargeting: true,
},
};
/// Creates parameters set for the given network. /// Creates parameters set for the given network.
pub const fn new(network: Network) -> Self {
match network {
Network::Bitcoin => Params::MAINNET,
Network::Testnet => Params::TESTNET,
Network::Signet => Params::SIGNET,
Network::Regtest => Params::REGTEST,
}
}
@ -121,6 +136,7 @@ impl From<Network> for Params {
fn from(value: Network) -> Self { Self::new(value) }
}
impl From<&Network> for Params {
fn from(value: &Network) -> Self { Self::new(*value) }
}