rustywallet_silent/
network.rs1use crate::error::{Result, SilentPaymentError};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum Network {
8 Mainnet,
10 Testnet,
12}
13
14impl Network {
15 pub fn hrp(&self) -> &'static str {
17 match self {
18 Network::Mainnet => "sp",
19 Network::Testnet => "tsp",
20 }
21 }
22
23 pub fn from_hrp(hrp: &str) -> Result<Self> {
25 match hrp {
26 "sp" => Ok(Network::Mainnet),
27 "tsp" => Ok(Network::Testnet),
28 _ => Err(SilentPaymentError::InvalidNetwork(format!(
29 "Unknown HRP: {}",
30 hrp
31 ))),
32 }
33 }
34}
35
36impl std::fmt::Display for Network {
37 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38 match self {
39 Network::Mainnet => write!(f, "mainnet"),
40 Network::Testnet => write!(f, "testnet"),
41 }
42 }
43}