zebra/zebra-chain/src/parameters/network.rs

52 lines
1.2 KiB
Rust
Raw Normal View History

use std::{convert::From, fmt};
#[cfg(any(test, feature = "proptest-impl"))]
use proptest_derive::Arbitrary;
/// An enum describing the possible network choices.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[cfg_attr(any(test, feature = "proptest-impl"), derive(Arbitrary))]
pub enum Network {
/// The production mainnet.
Mainnet,
/// The testnet.
Testnet,
}
impl From<&Network> for &'static str {
fn from(network: &Network) -> &'static str {
match network {
Network::Mainnet => "Mainnet",
Network::Testnet => "Testnet",
}
}
}
impl From<Network> for &'static str {
fn from(network: Network) -> &'static str {
(&network).into()
}
}
impl fmt::Display for Network {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.into())
}
}
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,
}
}
}
impl Default for Network {
fn default() -> Self {
Network::Mainnet
}
}