use crate::network::constants::Network;
use crate::pow::Work;
#[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,
pub pow_limit: Work,
pub pow_target_spacing: u64,
pub pow_target_timespan: u64,
pub allow_min_difficulty_blocks: bool,
pub no_pow_retargeting: bool,
}
impl Params {
pub fn new(network: Network) -> Self {
match network {
Network::Bitcoin => 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: Work::MAINNET_MIN,
pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: false,
no_pow_retargeting: false,
},
Network::Testnet => 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: Work::TESTNET_MIN,
pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: true,
no_pow_retargeting: false,
},
Network::Signet => 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: Work::SIGNET_MIN,
pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: false,
no_pow_retargeting: false,
},
Network::Regtest => 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: Work::REGTEST_MIN,
pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: true,
no_pow_retargeting: true,
},
}
}
pub fn difficulty_adjustment_interval(&self) -> u64 {
self.pow_target_timespan / self.pow_target_spacing
}
}