forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9616d0
commit 8961ab5
Showing
7 changed files
with
111 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "solana-cluster-type" | ||
description = "Solana ClusterType enum" | ||
documentation = "https://docs.rs/solana-cluster-type" | ||
version = { workspace = true } | ||
authors = { workspace = true } | ||
repository = { workspace = true } | ||
homepage = { workspace = true } | ||
license = { workspace = true } | ||
edition = { workspace = true } | ||
|
||
[dependencies] | ||
serde = { workspace = true, optional = true } | ||
serde_derive = { workspace = true, optional = true } | ||
solana-frozen-abi = { workspace = true, optional = true } | ||
solana-frozen-abi-macro = { workspace = true, optional = true } | ||
solana-hash = { workspace = true, default-features = false } | ||
|
||
[features] | ||
frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] | ||
serde = ["dep:serde", "dep:serde_derive"] | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
all-features = true | ||
rustdoc-args = ["--cfg=docsrs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#![cfg_attr(feature = "frozen-abi", feature(min_specialization))] | ||
#![cfg_attr(docsrs, feature(doc_auto_cfg))] | ||
use {solana_hash::Hash, std::str::FromStr}; | ||
|
||
// The order can't align with release lifecycle only to remain ABI-compatible... | ||
#[cfg_attr(feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor))] | ||
#[cfg_attr( | ||
feature = "serde", | ||
derive(serde_derive::Deserialize, serde_derive::Serialize) | ||
)] | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
pub enum ClusterType { | ||
Testnet, | ||
MainnetBeta, | ||
Devnet, | ||
Development, | ||
} | ||
|
||
impl ClusterType { | ||
pub const STRINGS: [&'static str; 4] = ["development", "devnet", "testnet", "mainnet-beta"]; | ||
|
||
/// Get the known genesis hash for this ClusterType | ||
pub fn get_genesis_hash(&self) -> Option<Hash> { | ||
match self { | ||
Self::MainnetBeta => { | ||
Some(Hash::from_str("5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d").unwrap()) | ||
} | ||
Self::Testnet => { | ||
Some(Hash::from_str("4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2NsNY").unwrap()) | ||
} | ||
Self::Devnet => { | ||
Some(Hash::from_str("EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG").unwrap()) | ||
} | ||
Self::Development => None, | ||
} | ||
} | ||
} | ||
|
||
impl FromStr for ClusterType { | ||
type Err = String; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s { | ||
"development" => Ok(ClusterType::Development), | ||
"devnet" => Ok(ClusterType::Devnet), | ||
"testnet" => Ok(ClusterType::Testnet), | ||
"mainnet-beta" => Ok(ClusterType::MainnetBeta), | ||
_ => Err(format!("{s} is unrecognized for cluster type")), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters