2024-06-07 17:03:05 +01:00
|
|
|
use bft_json_crdt::json_crdt::BaseCrdt;
|
2024-06-06 19:32:29 +01:00
|
|
|
use cli::{parse_args, Commands};
|
2024-06-07 18:42:28 +01:00
|
|
|
use crdt::TransactionList;
|
2024-06-07 17:35:38 +01:00
|
|
|
use fastcrypto::ed25519::Ed25519KeyPair;
|
2024-06-07 17:03:05 +01:00
|
|
|
use node::SideNode;
|
|
|
|
|
use websocket::WebSocketClient;
|
2024-05-29 12:44:52 +01:00
|
|
|
|
2024-05-29 13:17:16 +01:00
|
|
|
pub(crate) mod cli;
|
2024-06-07 18:42:28 +01:00
|
|
|
pub(crate) mod crdt;
|
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-07 17:03:05 +01:00
|
|
|
pub(crate) mod node;
|
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-07 17:03:05 +01:00
|
|
|
let _ = init::init(utils::home(name), config);
|
2024-05-29 16:35:00 +01:00
|
|
|
}
|
2024-06-06 18:52:39 +01:00
|
|
|
Some(Commands::Run { name }) => {
|
2024-06-07 17:35:38 +01:00
|
|
|
let (crdt, websocket_client, keys) = setup(name);
|
|
|
|
|
let side_node = &mut SideNode::new(websocket_client, crdt, keys);
|
2024-06-07 17:03:05 +01:00
|
|
|
side_node.start().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-07 17:18:46 +01:00
|
|
|
/// Wire everything up outside the application so we can test more easily later
|
2024-06-07 17:35:38 +01:00
|
|
|
fn setup(name: &String) -> (BaseCrdt<TransactionList>, WebSocketClient, Ed25519KeyPair) {
|
2024-06-07 17:03:05 +01:00
|
|
|
let side_dir = utils::home(name);
|
|
|
|
|
let keys = keys::load_from_file(side_dir);
|
|
|
|
|
let websocket_client = WebSocketClient::new();
|
|
|
|
|
let crdt = BaseCrdt::<TransactionList>::new(&keys);
|
|
|
|
|
|
2024-06-07 17:35:38 +01:00
|
|
|
(crdt, websocket_client, keys)
|
2024-06-06 15:29:22 +01:00
|
|
|
}
|