use crate::network::Network;
#[cfg(doc)]
use crate::pow::CompactTarget;
use crate::pow::Target;
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct Params {
pub network: Network,
pub bip16_time: u32,
pub bip34_height: u32,
pub bip65_height: u32,
pub bip66_height: u32,
pub rule_change_activation_threshold: u32,
pub miner_confirmation_window: u32,
#[deprecated(since = "0.32.0", note = "field renamed to max_attainable_target")]
pub pow_limit: Target,
pub max_attainable_target: Target,
pub pow_target_spacing: u64,
pub pow_target_timespan: u64,
pub allow_min_difficulty_blocks: bool,
pub no_pow_retargeting: bool,
}
pub static MAINNET: Params = Params::MAINNET;
#[deprecated(since = "0.32.4", note = "Use TESTNET3 instead")]
pub static TESTNET: Params = Params::TESTNET3;
pub static TESTNET3: Params = Params::TESTNET3;
pub static TESTNET4: Params = Params::TESTNET4;
pub static SIGNET: Params = Params::SIGNET;
pub static REGTEST: Params = Params::REGTEST;
#[allow(deprecated)] impl Params {
pub const BITCOIN: Params = Params::MAINNET;
pub const MAINNET: Params = Params {
network: Network::Bitcoin,
bip16_time: 1333238400, bip34_height: 227931, bip65_height: 388381, bip66_height: 363725, rule_change_activation_threshold: 1916, miner_confirmation_window: 2016,
pow_limit: Target::MAX_ATTAINABLE_MAINNET,
max_attainable_target: Target::MAX_ATTAINABLE_MAINNET,
pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: false,
no_pow_retargeting: false,
};
#[deprecated(since = "0.32.4", note = "Use TESTNET3 instead")]
pub const TESTNET: Params = Params {
network: Network::Testnet,
bip16_time: 1333238400, bip34_height: 21111, bip65_height: 581885, bip66_height: 330776, rule_change_activation_threshold: 1512, miner_confirmation_window: 2016,
pow_limit: Target::MAX_ATTAINABLE_TESTNET,
max_attainable_target: Target::MAX_ATTAINABLE_TESTNET,
pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: true,
no_pow_retargeting: false,
};
pub const TESTNET3: Params = Params {
network: Network::Testnet,
bip16_time: 1333238400, bip34_height: 21111, bip65_height: 581885, bip66_height: 330776, rule_change_activation_threshold: 1512, miner_confirmation_window: 2016,
pow_limit: Target::MAX_ATTAINABLE_TESTNET,
max_attainable_target: Target::MAX_ATTAINABLE_TESTNET,
pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: true,
no_pow_retargeting: false,
};
pub const TESTNET4: Params = Params {
network: Network::Testnet4,
bip16_time: 1333238400, bip34_height: 1,
bip65_height: 1,
bip66_height: 1,
rule_change_activation_threshold: 1512, miner_confirmation_window: 2016,
pow_limit: Target::MAX_ATTAINABLE_TESTNET,
max_attainable_target: Target::MAX_ATTAINABLE_TESTNET,
pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: true,
no_pow_retargeting: false,
};
pub const SIGNET: Params = Params {
network: Network::Signet,
bip16_time: 1333238400, bip34_height: 1,
bip65_height: 1,
bip66_height: 1,
rule_change_activation_threshold: 1916, miner_confirmation_window: 2016,
pow_limit: Target::MAX_ATTAINABLE_SIGNET,
max_attainable_target: Target::MAX_ATTAINABLE_SIGNET,
pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: false,
no_pow_retargeting: false,
};
pub const REGTEST: Params = Params {
network: Network::Regtest,
bip16_time: 1333238400, bip34_height: 100000000, bip65_height: 1351,
bip66_height: 1251, rule_change_activation_threshold: 108, miner_confirmation_window: 144,
pow_limit: Target::MAX_ATTAINABLE_REGTEST,
max_attainable_target: Target::MAX_ATTAINABLE_REGTEST,
pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: true,
no_pow_retargeting: true,
};
pub const fn new(network: Network) -> Self {
match network {
Network::Bitcoin => Params::MAINNET,
Network::Testnet => Params::TESTNET3,
Network::Testnet4 => Params::TESTNET4,
Network::Signet => Params::SIGNET,
Network::Regtest => Params::REGTEST,
}
}
pub fn difficulty_adjustment_interval(&self) -> u64 {
self.pow_target_timespan / self.pow_target_spacing
}
}
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) }
}
impl From<Network> for &'static Params {
fn from(value: Network) -> Self { value.params() }
}
impl From<&Network> for &'static Params {
fn from(value: &Network) -> Self { value.params() }
}
impl AsRef<Params> for Params {
fn as_ref(&self) -> &Params { self }
}
impl AsRef<Params> for Network {
fn as_ref(&self) -> &Params { Self::params(*self) }
}