1use crate::network::Network;
10#[cfg(doc)]
11use crate::pow::CompactTarget;
12use crate::pow::Target;
13
14#[non_exhaustive]
16#[derive(Debug, Clone)]
17pub struct Params {
18 pub network: Network,
20 pub bip16_time: u32,
22 pub bip34_height: u32,
24 pub bip65_height: u32,
26 pub bip66_height: u32,
28 pub rule_change_activation_threshold: u32,
32 pub miner_confirmation_window: u32,
34 #[deprecated(since = "0.32.0", note = "field renamed to max_attainable_target")]
36 pub pow_limit: Target,
37 pub max_attainable_target: Target,
49 pub pow_target_spacing: u64,
51 pub pow_target_timespan: u64,
53 pub allow_min_difficulty_blocks: bool,
55 pub no_pow_retargeting: bool,
57}
58
59pub static MAINNET: Params = Params::MAINNET;
67#[deprecated(since = "0.32.4", note = "Use TESTNET3 instead")]
69pub static TESTNET: Params = Params::TESTNET3;
70pub static TESTNET3: Params = Params::TESTNET3;
72pub static TESTNET4: Params = Params::TESTNET4;
74pub static SIGNET: Params = Params::SIGNET;
76pub static REGTEST: Params = Params::REGTEST;
78
79#[allow(deprecated)] impl Params {
81 pub const BITCOIN: Params = Params::MAINNET;
83
84 pub const MAINNET: Params = Params {
86 network: Network::Bitcoin,
87 bip16_time: 1333238400, bip34_height: 227931, bip65_height: 388381, bip66_height: 363725, rule_change_activation_threshold: 1916, miner_confirmation_window: 2016,
93 pow_limit: Target::MAX_ATTAINABLE_MAINNET,
94 max_attainable_target: Target::MAX_ATTAINABLE_MAINNET,
95 pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: false,
98 no_pow_retargeting: false,
99 };
100
101 #[deprecated(since = "0.32.4", note = "Use TESTNET3 instead")]
103 pub const TESTNET: Params = Params {
104 network: Network::Testnet,
105 bip16_time: 1333238400, bip34_height: 21111, bip65_height: 581885, bip66_height: 330776, rule_change_activation_threshold: 1512, miner_confirmation_window: 2016,
111 pow_limit: Target::MAX_ATTAINABLE_TESTNET,
112 max_attainable_target: Target::MAX_ATTAINABLE_TESTNET,
113 pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: true,
116 no_pow_retargeting: false,
117 };
118
119 pub const TESTNET3: Params = Params {
121 network: Network::Testnet,
122 bip16_time: 1333238400, bip34_height: 21111, bip65_height: 581885, bip66_height: 330776, rule_change_activation_threshold: 1512, miner_confirmation_window: 2016,
128 pow_limit: Target::MAX_ATTAINABLE_TESTNET,
129 max_attainable_target: Target::MAX_ATTAINABLE_TESTNET,
130 pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: true,
133 no_pow_retargeting: false,
134 };
135
136 pub const TESTNET4: Params = Params {
138 network: Network::Testnet4,
139 bip16_time: 1333238400, bip34_height: 1,
141 bip65_height: 1,
142 bip66_height: 1,
143 rule_change_activation_threshold: 1512, miner_confirmation_window: 2016,
145 pow_limit: Target::MAX_ATTAINABLE_TESTNET,
146 max_attainable_target: Target::MAX_ATTAINABLE_TESTNET,
147 pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: true,
150 no_pow_retargeting: false,
151 };
152
153 pub const SIGNET: Params = Params {
155 network: Network::Signet,
156 bip16_time: 1333238400, bip34_height: 1,
158 bip65_height: 1,
159 bip66_height: 1,
160 rule_change_activation_threshold: 1916, miner_confirmation_window: 2016,
162 pow_limit: Target::MAX_ATTAINABLE_SIGNET,
163 max_attainable_target: Target::MAX_ATTAINABLE_SIGNET,
164 pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: false,
167 no_pow_retargeting: false,
168 };
169
170 pub const REGTEST: Params = Params {
172 network: Network::Regtest,
173 bip16_time: 1333238400, bip34_height: 100000000, bip65_height: 1351,
176 bip66_height: 1251, rule_change_activation_threshold: 108, miner_confirmation_window: 144,
179 pow_limit: Target::MAX_ATTAINABLE_REGTEST,
180 max_attainable_target: Target::MAX_ATTAINABLE_REGTEST,
181 pow_target_spacing: 10 * 60, pow_target_timespan: 14 * 24 * 60 * 60, allow_min_difficulty_blocks: true,
184 no_pow_retargeting: true,
185 };
186
187 pub const fn new(network: Network) -> Self {
189 match network {
190 Network::Bitcoin => Params::MAINNET,
191 Network::Testnet => Params::TESTNET3,
192 Network::Testnet4 => Params::TESTNET4,
193 Network::Signet => Params::SIGNET,
194 Network::Regtest => Params::REGTEST,
195 }
196 }
197
198 pub fn difficulty_adjustment_interval(&self) -> u64 {
200 self.pow_target_timespan / self.pow_target_spacing
201 }
202}
203
204impl From<Network> for Params {
205 fn from(value: Network) -> Self { Self::new(value) }
206}
207
208impl From<&Network> for Params {
209 fn from(value: &Network) -> Self { Self::new(*value) }
210}
211
212impl From<Network> for &'static Params {
213 fn from(value: Network) -> Self { value.params() }
214}
215
216impl From<&Network> for &'static Params {
217 fn from(value: &Network) -> Self { value.params() }
218}
219
220impl AsRef<Params> for Params {
221 fn as_ref(&self) -> &Params { self }
222}
223
224impl AsRef<Params> for Network {
225 fn as_ref(&self) -> &Params { Self::params(*self) }
226}