2024-06-06 19:32:29 +01:00
|
|
|
use cli::{parse_args, Commands};
|
2024-05-29 12:44:52 +01:00
|
|
|
|
2024-05-29 13:17:16 +01:00
|
|
|
pub(crate) mod cli;
|
2024-05-29 16:47:35 +01:00
|
|
|
pub(crate) mod init;
|
2024-06-06 18:52:39 +01:00
|
|
|
pub(crate) mod keys;
|
2024-06-05 19:49:13 +01:00
|
|
|
pub(crate) mod list_transaction_crdt;
|
2024-06-06 18:52:39 +01:00
|
|
|
pub(crate) mod utils;
|
2024-05-29 16:35:00 +01:00
|
|
|
pub(crate) mod websocket;
|
2024-05-29 13:17:16 +01:00
|
|
|
|
2024-05-29 12:44:52 +01:00
|
|
|
#[tokio::main]
|
2024-05-29 16:35:00 +01:00
|
|
|
async fn main() {
|
|
|
|
|
let args = parse_args();
|
2024-05-29 12:44:52 +01:00
|
|
|
|
2024-05-29 16:35:00 +01:00
|
|
|
match &args.command {
|
2024-06-06 16:02:00 +01:00
|
|
|
Some(Commands::Init { name }) => {
|
2024-06-06 15:54:33 +01:00
|
|
|
let config = init::config::SideNodeConfig {
|
2024-06-06 16:02:00 +01:00
|
|
|
name: name.to_string(),
|
2024-06-06 15:54:33 +01:00
|
|
|
};
|
|
|
|
|
|
2024-06-06 16:07:11 +01:00
|
|
|
let _ = init::init(home(name), config);
|
2024-05-29 16:35:00 +01:00
|
|
|
}
|
2024-06-06 18:52:39 +01:00
|
|
|
Some(Commands::Run { name }) => {
|
|
|
|
|
let side_dir = home(name);
|
|
|
|
|
let (mut bft_crdt, keys) = list_transaction_crdt::new(side_dir);
|
2024-06-06 19:32:29 +01:00
|
|
|
websocket::start(keys, &mut bft_crdt).await;
|
2024-05-29 16:35:00 +01:00
|
|
|
}
|
2024-05-29 16:47:35 +01:00
|
|
|
None => println!("No command provided. Exiting. See --help for more information."),
|
2024-05-29 12:44:52 +01:00
|
|
|
}
|
2024-05-29 08:32:40 +01:00
|
|
|
}
|
2024-06-06 15:29:22 +01:00
|
|
|
|
2024-06-06 16:07:11 +01:00
|
|
|
fn home(name: &String) -> std::path::PathBuf {
|
2024-06-06 15:29:22 +01:00
|
|
|
let mut path = dirs::home_dir().unwrap();
|
|
|
|
|
path.push(".side");
|
2024-06-06 16:07:11 +01:00
|
|
|
path.push(name);
|
2024-06-06 15:29:22 +01:00
|
|
|
path
|
|
|
|
|
}
|