diff --git a/side-node/src/list_transaction_crdt.rs b/side-node/src/list_transaction_crdt.rs index eae3822..9192b02 100644 --- a/side-node/src/list_transaction_crdt.rs +++ b/side-node/src/list_transaction_crdt.rs @@ -10,7 +10,6 @@ use bft_json_crdt::{ use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; -use websockets::WebSocket; use crate::keys; @@ -39,9 +38,9 @@ pub(crate) fn new(side_dir: PathBuf) -> (BaseCrdt, Ed25519KeyPair) { pub(crate) async fn send( count: u32, bft_crdt: &mut BaseCrdt, - ws: &mut WebSocket, + // ws: &mut WebSocket, keys: &Ed25519KeyPair, -) -> Result<(), websockets::WebSocketError> { +) { // generate a placeholder transaction let transaction = generate_transaction(count, keys.public().to_string()); @@ -53,9 +52,9 @@ pub(crate) async fn send( .insert_idx(next - 1, transaction.clone()) .sign(&keys); - Ok(ws - .send_text(serde_json::to_string(&signed_op).unwrap()) - .await?) + // Ok(ws + // .send_text(serde_json::to_string(&signed_op).unwrap()) + // .await?) } fn generate_transaction(count: u32, pubkey: String) -> Value { diff --git a/side-node/src/main.rs b/side-node/src/main.rs index d65cd7d..f369ea6 100644 --- a/side-node/src/main.rs +++ b/side-node/src/main.rs @@ -1,4 +1,4 @@ -/** use cli::{parse_args, Commands}; +use cli::{parse_args, Commands}; pub(crate) mod cli; pub(crate) mod init; @@ -22,7 +22,7 @@ async fn main() { 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.unwrap(); + websocket::start(keys, &mut bft_crdt).await; } None => println!("No command provided. Exiting. See --help for more information."), } @@ -34,46 +34,3 @@ fn home(name: &String) -> std::path::PathBuf { path.push(name); path } -**/ -use async_trait::async_trait; -use ezsockets::ClientConfig; -use std::io::BufRead; - -struct Client {} - -#[async_trait] -impl ezsockets::ClientExt for Client { - type Call = (); - - async fn on_text(&mut self, text: String) -> Result<(), ezsockets::Error> { - tracing::info!("received message: {text}"); - Ok(()) - } - - async fn on_binary(&mut self, bytes: Vec) -> Result<(), ezsockets::Error> { - tracing::info!("received bytes: {bytes:?}"); - Ok(()) - } - - async fn on_call(&mut self, call: Self::Call) -> Result<(), ezsockets::Error> { - let () = call; - Ok(()) - } -} - -#[tokio::main] -async fn main() { - tracing_subscriber::fmt::init(); - let config = ClientConfig::new("ws://localhost:8080/websocket"); - let (handle, future) = ezsockets::connect(|_client| Client {}, config).await; - tokio::spawn(async move { - future.await.unwrap(); - }); - let stdin = std::io::stdin(); - let lines = stdin.lock().lines(); - for line in lines { - let line = line.unwrap(); - tracing::info!("sending {line}"); - handle.text(line).unwrap(); - } -} diff --git a/side-node/src/websocket/mod.rs b/side-node/src/websocket/mod.rs index f795924..60c380d 100644 --- a/side-node/src/websocket/mod.rs +++ b/side-node/src/websocket/mod.rs @@ -21,3 +21,49 @@ loop { } */ + +use async_trait::async_trait; +use bft_json_crdt::json_crdt::BaseCrdt; +use ezsockets::ClientConfig; +use fastcrypto::ed25519::Ed25519KeyPair; +use std::io::BufRead; + +use crate::list_transaction_crdt::CrdtList; + +struct Client {} + +#[async_trait] +impl ezsockets::ClientExt for Client { + type Call = (); + + async fn on_text(&mut self, text: String) -> Result<(), ezsockets::Error> { + tracing::info!("received message: {text}"); + Ok(()) + } + + async fn on_binary(&mut self, bytes: Vec) -> Result<(), ezsockets::Error> { + tracing::info!("received bytes: {bytes:?}"); + Ok(()) + } + + async fn on_call(&mut self, call: Self::Call) -> Result<(), ezsockets::Error> { + let () = call; + Ok(()) + } +} + +pub(crate) async fn start(keys: Ed25519KeyPair, bft_crdt: &mut BaseCrdt) { + tracing_subscriber::fmt::init(); + let config = ClientConfig::new("ws://localhost:8080/websocket"); + let (handle, future) = ezsockets::connect(|_client| Client {}, config).await; + tokio::spawn(async move { + future.await.unwrap(); + }); + let stdin = std::io::stdin(); + let lines = stdin.lock().lines(); + for line in lines { + let line = line.unwrap(); + tracing::info!("sending {line}"); + handle.text(line).unwrap(); + } +}