use clap::Subcommand;
use color_eyre::{eyre::Result, Section};
use sn_evm::{utils::get_evm_network_from_env, EvmNetwork};
#[derive(Subcommand, Clone, Debug)]
#[allow(clippy::enum_variant_names)]
pub enum EvmNetworkCommand {
EvmArbitrumOne,
EvmArbitrumSepolia,
EvmCustom {
#[arg(long)]
rpc_url: String,
#[arg(long, short)]
payment_token_address: String,
#[arg(long, short)]
data_payments_address: String,
},
EvmLocal,
}
impl TryInto<EvmNetwork> for EvmNetworkCommand {
type Error = color_eyre::eyre::Error;
fn try_into(self) -> Result<EvmNetwork> {
match self {
Self::EvmArbitrumOne => Ok(EvmNetwork::ArbitrumOne),
Self::EvmArbitrumSepolia => Ok(EvmNetwork::ArbitrumSepolia),
Self::EvmLocal => {
if !cfg!(feature = "local") {
return Err(color_eyre::eyre::eyre!(
"The 'local' feature flag is not enabled."
))
.suggestion("Enable the 'local' feature flag to use the local EVM testnet.");
}
let network = get_evm_network_from_env()?;
Ok(network)
}
Self::EvmCustom {
rpc_url,
payment_token_address,
data_payments_address,
} => Ok(EvmNetwork::new_custom(
&rpc_url,
&payment_token_address,
&data_payments_address,
)),
}
}
}