1use bitcoin::Network as BtcNetwork;
4use core::fmt;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
8pub enum Network {
9 #[default]
11 Mainnet,
12 Testnet,
14}
15
16impl Network {
17 #[inline]
19 #[must_use]
20 pub const fn to_bitcoin_network(self) -> BtcNetwork {
21 match self {
22 Self::Mainnet => BtcNetwork::Bitcoin,
23 Self::Testnet => BtcNetwork::Testnet,
24 }
25 }
26
27 #[inline]
29 #[must_use]
30 pub const fn coin_type(self) -> u32 {
31 match self {
32 Self::Mainnet => 0,
33 Self::Testnet => 1,
34 }
35 }
36
37 #[inline]
39 #[must_use]
40 pub const fn name(self) -> &'static str {
41 match self {
42 Self::Mainnet => "mainnet",
43 Self::Testnet => "testnet",
44 }
45 }
46}
47
48impl fmt::Display for Network {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 write!(f, "{}", self.name())
51 }
52}