wallet_adapter_common/
clusters.rs

1/// Solana Mainnet cluster
2pub const MAINNET_ENDPOINT: &str = "https://api.mainnet-beta.solana.com";
3/// Solana Devnet cluster
4pub const DEVNET_ENDPOINT: &str = "https://api.devnet.solana.com";
5/// Solana Testnet cluster
6pub const TESTNET_ENDPOINT: &str = "https://api.testnet.solana.com";
7/// Solana Localnet cluster
8pub const LOCALNET_ENDPOINT: &str = "http://localhost:8899";
9
10/// Solana Mainnet cluster,  [https://api.mainnet-beta.solana.com](https://api.mainnet-beta.solana.com)
11pub const MAINNET_IDENTIFIER: &str = "solana:mainnet";
12/// Solana Devnet cluster, e.g. [https://api.devnet.solana.com](https://api.devnet.solana.com)
13pub const DEVNET_IDENTIFIER: &str = "solana:devnet";
14/// Solana Testnet cluster, e.g. [https://api.testnet.solana.com](https://api.testnet.solana.com)
15pub const TESTNET_IDENTIFIER: &str = "solana:testnet";
16/// Solana Localnet cluster, e.g. [http://localhost:8899](http://localhost:8899)
17pub const LOCALNET_IDENTIFIER: &str = "solana:localnet";
18
19/// Solana Mainnet cluster,  [https://api.mainnet-beta.solana.com](https://api.mainnet-beta.solana.com)
20pub const MAINNET: &str = "mainnet";
21/// Solana Devnet cluster, e.g. [https://api.devnet.solana.com](https://api.devnet.solana.com)
22pub const DEVNET: &str = "devnet";
23/// Solana Testnet cluster, e.g. [https://api.testnet.solana.com](https://api.testnet.solana.com)
24pub const TESTNET: &str = "testnet";
25/// Solana Localnet cluster, e.g. [http://localhost:8899](http://localhost:8899)
26pub const LOCALNET: &str = "localnet";
27
28/// Solana Clusters
29#[derive(Debug, PartialEq, Eq, Default, PartialOrd, Ord, Clone, Copy, Hash)]
30pub enum Cluster {
31    /// Solana Mainnet cluster,  [https://api.mainnet-beta.solana.com](https://api.mainnet-beta.solana.com)
32    MainNet,
33    /// Solana Devnet cluster, e.g. [https://api.devnet.solana.com](https://api.devnet.solana.com)
34    #[default]
35    DevNet,
36    /// Solana Testnet cluster, e.g. [https://api.testnet.solana.com](https://api.testnet.solana.com)
37    TestNet,
38    /// Solana Localnet cluster, e.g. [http://localhost:8899](http://localhost:8899)
39    LocalNet,
40}
41
42impl Cluster {
43    /// A Solana endpoint URI
44    pub fn endpoint(&self) -> &str {
45        match self {
46            Cluster::MainNet => MAINNET_ENDPOINT,
47            Cluster::DevNet => DEVNET_ENDPOINT,
48            Cluster::TestNet => TESTNET_ENDPOINT,
49            Cluster::LocalNet => LOCALNET_ENDPOINT,
50        }
51    }
52
53    /// A Solana cluster identifier
54    pub fn chain(&self) -> &str {
55        match self {
56            Cluster::MainNet => MAINNET_IDENTIFIER,
57            Cluster::DevNet => DEVNET_IDENTIFIER,
58            Cluster::TestNet => TESTNET_IDENTIFIER,
59            Cluster::LocalNet => LOCALNET_IDENTIFIER,
60        }
61    }
62
63    /// A Solana cluster identifier as a &str
64    pub fn display(&self) -> &str {
65        match self {
66            Cluster::MainNet => MAINNET,
67            Cluster::DevNet => DEVNET,
68            Cluster::TestNet => TESTNET,
69            Cluster::LocalNet => LOCALNET,
70        }
71    }
72}
73
74impl core::fmt::Display for Cluster {
75    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
76        write!(f, "{}", self.display())
77    }
78}
79
80impl From<&str> for Cluster {
81    fn from(value: &str) -> Self {
82        match value {
83            MAINNET_IDENTIFIER => Self::MainNet,
84            DEVNET_IDENTIFIER => Self::DevNet,
85            TESTNET_IDENTIFIER => Self::TestNet,
86            LOCALNET_IDENTIFIER => Self::LocalNet,
87            MAINNET_ENDPOINT => Self::MainNet,
88            DEVNET_ENDPOINT => Self::DevNet,
89            TESTNET_ENDPOINT => Self::TestNet,
90            LOCALNET_ENDPOINT => Self::LocalNet,
91            MAINNET => Self::MainNet,
92            DEVNET => Self::DevNet,
93            TESTNET => Self::TestNet,
94            LOCALNET => Self::LocalNet,
95            _ => Self::DevNet,
96        }
97    }
98}