46 lines
1.4 KiB
Rust
46 lines
1.4 KiB
Rust
use bft_json_crdt::json_crdt::BaseCrdt;
|
|
use cli::{parse_args, Commands};
|
|
use crdt::TransactionList;
|
|
use fastcrypto::ed25519::Ed25519KeyPair;
|
|
use node::SideNode;
|
|
use websocket::WebSocketClient;
|
|
|
|
pub(crate) mod cli;
|
|
pub(crate) mod crdt;
|
|
pub(crate) mod init;
|
|
pub(crate) mod keys;
|
|
pub(crate) mod node;
|
|
pub(crate) mod utils;
|
|
pub(crate) mod websocket;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
let args = parse_args();
|
|
|
|
match &args.command {
|
|
Some(Commands::Init { name }) => {
|
|
let config = init::config::SideNodeConfig {
|
|
name: name.to_string(),
|
|
};
|
|
|
|
let _ = init::init(utils::home(name), config);
|
|
}
|
|
Some(Commands::Run { name }) => {
|
|
let (crdt, websocket_client, keys) = setup(name);
|
|
let side_node = &mut SideNode::new(websocket_client, crdt, keys);
|
|
side_node.start().await;
|
|
}
|
|
None => println!("No command provided. Exiting. See --help for more information."),
|
|
}
|
|
}
|
|
|
|
/// Wire everything up outside the application so we can test more easily later
|
|
fn setup(name: &String) -> (BaseCrdt<TransactionList>, WebSocketClient, Ed25519KeyPair) {
|
|
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, keys)
|
|
}
|