use contract_extrinsics::url_to_string;
use std::str::FromStr;
use url::Url;
macro_rules! define_chains {
(
$(#[$($attrs:tt)*])*
pub enum $root:ident { $( $c:ident = ($ep:tt, $config:tt) ),* $(,)? }
) => {
$(#[$($attrs)*])*
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum $root { $($c),* }
impl $root {
pub fn url(&self) -> url::Url {
match self {
$(
$root::$c => Url::parse($ep).expect("Incorrect Url format")
),*
}
}
pub fn config(&self) -> &str {
match self {
$(
$root::$c => $config
),*
}
}
pub fn from_parts(ep: &Url, config: &str) -> Option<Self> {
match (url_to_string(ep).as_str(), config) {
$(
($ep, $config) => Some($root::$c),
)*
_ => None
}
}
}
impl std::fmt::Display for $root {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
$(
$root::$c => f.write_str(stringify!($c))
),*
}
}
}
impl FromStr for $root {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
$(
stringify!($c) => Ok($root::$c),
)*
_ => Err(anyhow::anyhow!("Unrecognised chain name"))
}
}
}
};
}
define_chains! {
#[derive(clap::ValueEnum)]
pub enum ProductionChain {
AlephZero = ("wss://ws.azero.dev:443/", "Substrate"),
Astar = ("wss://rpc.astar.network:443/", "Polkadot"),
Shiden = ("wss://rpc.shiden.astar.network:443/", "Polkadot"),
Krest = ("wss://wss-krest.peaq.network:443/", "Polkadot")
}
}