2022-08-29 20:54:58 +00:00
|
|
|
use clap::Parser;
|
2022-09-09 22:14:17 +00:00
|
|
|
use common::utils::hex_str_to_bytes;
|
2022-08-29 20:54:58 +00:00
|
|
|
use dirs::home_dir;
|
2022-09-09 01:34:14 +00:00
|
|
|
use env_logger::Env;
|
2022-08-11 18:09:58 +00:00
|
|
|
use eyre::Result;
|
2022-08-16 22:59:07 +00:00
|
|
|
|
2022-09-10 04:01:23 +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
|
|
|
|
2022-08-11 18:09:58 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
2022-09-09 01:34:14 +00:00
|
|
|
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
|
|
|
|
|
2022-09-10 04:01:23 +00:00
|
|
|
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();
|
2022-09-09 22:14:17 +00:00
|
|
|
let mut config = match cli.network.as_str() {
|
2022-09-15 21:56:42 +00:00
|
|
|
"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
|
|
|
|
2022-09-09 22:14:17 +00:00
|
|
|
if let Some(checkpoint) = cli.checkpoint {
|
|
|
|
config.general.checkpoint = hex_str_to_bytes(&checkpoint)?;
|
|
|
|
}
|
|
|
|
|
2022-09-10 04:01:23 +00:00
|
|
|
if let Some(port) = cli.port {
|
|
|
|
config.general.rpc_port = Some(port);
|
2022-08-31 00:31:58 +00:00
|
|
|
}
|
2022-09-10 04:01:23 +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;
|
|
|
|
}
|
|
|
|
|
2022-09-10 04:01:23 +00:00
|
|
|
Ok(config)
|
2022-08-11 18:09:58 +00:00
|
|
|
}
|
2022-08-29 20:54:58 +00:00
|
|
|
|
|
|
|
#[derive(Parser)]
|
|
|
|
struct Cli {
|
2022-09-15 21:56:42 +00:00
|
|
|
#[clap(short, long, default_value = "mainnet")]
|
2022-08-29 20:54:58 +00:00
|
|
|
network: String,
|
2022-09-10 04:01:23 +00:00
|
|
|
#[clap(short, long)]
|
|
|
|
port: Option<u16>,
|
2022-09-13 00:36:04 +00:00
|
|
|
#[clap(short = 'w', long)]
|
2022-09-09 22:14:17 +00:00
|
|
|
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
|
|
|
}
|