Splitting side-node crate into lib/bin for integration tests
This commit is contained in:
@@ -1,56 +1,5 @@
|
||||
use bft_json_crdt::json_crdt::{BaseCrdt, SignedOp};
|
||||
use cli::{parse_args, Commands};
|
||||
use crdt::TransactionList;
|
||||
use node::SideNode;
|
||||
use tokio::{sync::mpsc, task};
|
||||
use websocket::WebSocketClient;
|
||||
use side_node;
|
||||
|
||||
pub(crate) mod cli;
|
||||
pub(crate) mod crdt;
|
||||
pub(crate) mod init;
|
||||
pub(crate) mod keys;
|
||||
pub(crate) mod node;
|
||||
pub(crate) mod stdin;
|
||||
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 mut node = setup(name).await;
|
||||
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
|
||||
async fn setup(name: &String) -> SideNode {
|
||||
// First, load up the keys and create a bft-crdt
|
||||
let side_dir = utils::home(name);
|
||||
let keys = keys::load_from_file(side_dir);
|
||||
let crdt = BaseCrdt::<TransactionList>::new(&keys);
|
||||
|
||||
// Channels for internal communication, and a tokio task for stdin input
|
||||
let (incoming_sender, incoming_receiver) = mpsc::channel::<SignedOp>(32);
|
||||
let (stdin_sender, stdin_receiver) = std::sync::mpsc::channel();
|
||||
task::spawn(async move {
|
||||
stdin::input(stdin_sender);
|
||||
});
|
||||
|
||||
// Finally, create the node and return it
|
||||
let handle = WebSocketClient::new(incoming_sender).await;
|
||||
let node = SideNode::new(crdt, keys, incoming_receiver, stdin_receiver, handle);
|
||||
println!("Node setup complete.");
|
||||
node
|
||||
fn main() {
|
||||
side_node::run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user