use std::ffi::OsString;
use super::subcommands::Cli;
use crate::networks::NetworkChain;
use crate::rpc::{self, prelude::*};
use crate::shim::address::{CurrentNetwork, Network};
use clap::Parser;
use std::str::FromStr;
pub async fn main<ArgT>(args: impl IntoIterator<Item = ArgT>) -> anyhow::Result<()>
where
ArgT: Into<OsString> + Clone,
{
let client = rpc::Client::default_or_from_env(None)?;
if let Ok(name) = StateNetworkName::call(&client, ()).await
&& !matches!(NetworkChain::from_str(&name), Ok(NetworkChain::Mainnet))
{
CurrentNetwork::set_global(Network::Testnet);
}
let Cli {
opts,
remote_wallet,
encrypt,
cmd,
} = Cli::parse_from(args);
let client = rpc::Client::default_or_from_env(opts.token.as_deref())?;
cmd.run(client, remote_wallet, encrypt).await
}