helios/cli/src/main.rs

45 lines
1.1 KiB
Rust
Raw Normal View History

2022-08-29 20:54:58 +00:00
use std::{sync::Arc, time::Duration};
2022-08-20 17:18:40 +00:00
2022-08-29 20:54:58 +00:00
use clap::Parser;
use dirs::home_dir;
use eyre::Result;
2022-08-31 00:31:58 +00:00
use tokio::{sync::Mutex, time::sleep};
2022-08-16 22:59:07 +00:00
2022-08-26 01:18:47 +00:00
use client::{rpc::Rpc, 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<()> {
2022-08-29 20:54:58 +00:00
let cli = Cli::parse();
let config = match cli.network.as_str() {
"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-08-27 00:05:12 +00:00
let mut client = Client::new(Arc::new(config)).await?;
2022-08-19 22:43:58 +00:00
client.sync().await?;
2022-08-19 00:33:44 +00:00
2022-08-31 00:31:58 +00:00
let client = Arc::new(Mutex::new(client));
let mut rpc = Rpc::new(client.clone(), cli.port.unwrap_or(8545));
2022-08-26 01:18:47 +00:00
let addr = rpc.start().await?;
2022-08-29 20:54:58 +00:00
println!("started rpc at: {}", addr);
2022-08-24 01:33:48 +00:00
2022-08-31 00:31:58 +00:00
loop {
sleep(Duration::from_secs(10)).await;
client.lock().await.advance().await?
}
}
2022-08-29 20:54:58 +00:00
#[derive(Parser)]
struct Cli {
#[clap(long)]
network: String,
#[clap(long)]
port: Option<u16>,
}