2021-04-19 13:48:14 -07:00
|
|
|
use std::{convert::From, fmt};
|
2020-10-30 12:36:20 -07:00
|
|
|
|
2021-06-17 17:05:28 -07:00
|
|
|
use crate::{block::Height, parameters::NetworkUpgrade::Canopy};
|
|
|
|
|
2020-09-23 18:52:52 -07:00
|
|
|
#[cfg(any(test, feature = "proptest-impl"))]
|
2020-08-15 15:45:37 -07:00
|
|
|
use proptest_derive::Arbitrary;
|
|
|
|
|
|
|
|
/// An enum describing the possible network choices.
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
2020-09-23 18:52:52 -07:00
|
|
|
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
|
2020-08-15 15:45:37 -07:00
|
|
|
pub enum Network {
|
|
|
|
/// The production mainnet.
|
|
|
|
Mainnet,
|
|
|
|
/// The testnet.
|
|
|
|
Testnet,
|
|
|
|
}
|
|
|
|
|
2021-04-19 13:48:14 -07:00
|
|
|
impl From<&Network> for &'static str {
|
|
|
|
fn from(network: &Network) -> &'static str {
|
|
|
|
match network {
|
|
|
|
Network::Mainnet => "Mainnet",
|
|
|
|
Network::Testnet => "Testnet",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-21 15:14:36 -07:00
|
|
|
impl From<Network> for &'static str {
|
|
|
|
fn from(network: Network) -> &'static str {
|
|
|
|
(&network).into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-30 12:36:20 -07:00
|
|
|
impl fmt::Display for Network {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2021-04-19 13:48:14 -07:00
|
|
|
f.write_str(self.into())
|
2020-10-30 12:36:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-04 10:19:20 -07:00
|
|
|
impl Network {
|
|
|
|
/// Get the default port associated to this network.
|
|
|
|
pub fn default_port(&self) -> u16 {
|
|
|
|
match self {
|
|
|
|
Network::Mainnet => 8233,
|
|
|
|
Network::Testnet => 18233,
|
|
|
|
}
|
|
|
|
}
|
2021-06-17 17:05:28 -07:00
|
|
|
|
|
|
|
/// Get the mandatory minimum checkpoint height for this network.
|
|
|
|
///
|
|
|
|
/// Mandatory checkpoints are a Zebra-specific feature.
|
|
|
|
/// If a Zcash consensus rule only applies before the mandatory checkpoint,
|
|
|
|
/// Zebra can skip validation of that rule.
|
|
|
|
pub fn mandatory_checkpoint_height(&self) -> Height {
|
|
|
|
// Currently this is the Canopy activation height for both networks.
|
|
|
|
Canopy
|
|
|
|
.activation_height(*self)
|
|
|
|
.expect("Canopy activation height must be present for both networks")
|
|
|
|
}
|
2020-09-04 10:19:20 -07:00
|
|
|
}
|
|
|
|
|
2020-08-15 15:45:37 -07:00
|
|
|
impl Default for Network {
|
|
|
|
fn default() -> Self {
|
|
|
|
Network::Mainnet
|
|
|
|
}
|
|
|
|
}
|