helios/cli/src/main.rs

65 lines
1.6 KiB
Rust
Raw Normal View History

2022-08-29 20:54:58 +00:00
use clap::Parser;
use common::utils::hex_str_to_bytes;
2022-08-29 20:54:58 +00:00
use dirs::home_dir;
use env_logger::Env;
use eyre::Result;
2022-08-16 22:59:07 +00:00
use client::Client;
2022-08-29 20:54:58 +00:00
use config::{networks, Config};
2022-08-24 01:33:48 +00:00
#[tokio::main]
async fn main() -> Result<()> {
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
let config = get_config()?;
let mut client = Client::new(config).await?;
client.start().await?;
std::future::pending().await
}
fn get_config() -> Result<Config> {
2022-08-29 20:54:58 +00:00
let cli = Cli::parse();
let mut config = match cli.network.as_str() {
"mainnet" => networks::mainnet(),
2022-08-29 20:54:58 +00:00
"goerli" => networks::goerli(),
_ => {
let home = home_dir().unwrap();
let config_path = home.join(format!(".lightclient/configs/{}.toml", cli.network));
Config::from_file(&config_path).unwrap()
}
};
2022-08-20 20:33:32 +00:00
if let Some(checkpoint) = cli.checkpoint {
config.general.checkpoint = hex_str_to_bytes(&checkpoint)?;
}
if let Some(port) = cli.port {
config.general.rpc_port = Some(port);
2022-08-31 00:31:58 +00:00
}
2022-09-13 00:36:04 +00:00
if let Some(execution_rpc) = cli.execution_rpc {
config.general.execution_rpc = execution_rpc;
}
if let Some(consensus_rpc) = cli.consensus_rpc {
config.general.consensus_rpc = consensus_rpc;
}
Ok(config)
}
2022-08-29 20:54:58 +00:00
#[derive(Parser)]
struct Cli {
#[clap(short, long, default_value = "mainnet")]
2022-08-29 20:54:58 +00:00
network: String,
#[clap(short, long)]
port: Option<u16>,
2022-09-13 00:36:04 +00:00
#[clap(short = 'w', long)]
checkpoint: Option<String>,
2022-09-13 00:36:04 +00:00
#[clap(short, long)]
execution_rpc: Option<String>,
#[clap(short, long)]
consensus_rpc: Option<String>,
2022-08-29 20:54:58 +00:00
}