use crate::prelude::*;
use std::{
fmt::{self, Display},
process,
};
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Network {
CosmosHub,
IrisHub,
SentinelHub,
Osmosis,
Persistence,
}
impl Display for Network {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Network::CosmosHub => "cosmoshub",
Network::IrisHub => "irishub",
Network::SentinelHub => "sentinelhub",
Network::Osmosis => "osmosis",
Network::Persistence => "core",
})
}
}
impl Network {
pub fn all() -> &'static [Network] {
&[
Network::CosmosHub,
Network::IrisHub,
Network::SentinelHub,
Network::Osmosis,
Network::Persistence,
]
}
pub fn parse(s: &str) -> Self {
match s {
"cosmoshub" => Network::CosmosHub,
"irishub" => Network::IrisHub,
"sentinelhub" => Network::SentinelHub,
"osmosis" => Network::Osmosis,
"core" => Network::Persistence,
other => {
status_err!("unknown CometBFT network: `{}`", other);
eprintln!("\nRegistered networks:");
for network in Self::all() {
eprintln!("- {network}");
}
process::exit(1);
}
}
}
pub fn chain_id(&self) -> &str {
match self {
Network::CosmosHub => "cosmoshub-3",
Network::IrisHub => "irishub",
Network::SentinelHub => "sentinelhub-2",
Network::Osmosis => "osmosis-1",
Network::Persistence => "core-1",
}
}
pub fn schema_file(&self) -> &str {
match self {
Network::CosmosHub => "cosmos-sdk.toml",
Network::IrisHub => "iris.toml",
Network::SentinelHub => "sentinelhub.toml",
Network::Osmosis => "osmosis.toml",
Network::Persistence => "persistence.toml",
}
}
}