Starting to modify things into container structs

This commit is contained in:
Dave Hrycyszyn
2024-06-07 17:03:05 +01:00
parent b1f5d2b75a
commit a81d1f913a
5 changed files with 100 additions and 55 deletions

View File

@@ -1,9 +1,14 @@
use bft_json_crdt::json_crdt::BaseCrdt;
use cli::{parse_args, Commands};
use list_transaction_crdt::TransactionList;
use node::SideNode;
use websocket::WebSocketClient;
pub(crate) mod cli;
pub(crate) mod init;
pub(crate) mod keys;
pub(crate) mod list_transaction_crdt;
pub(crate) mod node;
pub(crate) mod utils;
pub(crate) mod websocket;
@@ -17,20 +22,23 @@ async fn main() {
name: name.to_string(),
};
let _ = init::init(home(name), config);
let _ = init::init(utils::home(name), config);
}
Some(Commands::Run { name }) => {
let side_dir = home(name);
let (mut bft_crdt, keys) = list_transaction_crdt::new(side_dir);
websocket::start(keys, &mut bft_crdt).await;
let (crdt, websocket_client) = setup(name);
let side_node = &mut SideNode::new(websocket_client, crdt, name.to_owned());
side_node.start().await;
}
None => println!("No command provided. Exiting. See --help for more information."),
}
}
fn home(name: &String) -> std::path::PathBuf {
let mut path = dirs::home_dir().unwrap();
path.push(".side");
path.push(name);
path
fn setup(name: &String) -> (BaseCrdt<TransactionList>, WebSocketClient) {
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);
(crdt, websocket_client)
}