diff --git a/side-node/src/cli/mod.rs b/side-node/src/cli/mod.rs index cf50b6f..d20431d 100644 --- a/side-node/src/cli/mod.rs +++ b/side-node/src/cli/mod.rs @@ -17,6 +17,9 @@ pub(crate) struct Args { #[derive(Subcommand)] pub(crate) enum Commands { + /// Placeholder for future BTC commands + Btc {}, + /// runs the Side Node Run { name: String }, diff --git a/side-node/src/clients/btc.rs b/side-node/src/clients/btc.rs new file mode 100644 index 0000000..dc5359c --- /dev/null +++ b/side-node/src/clients/btc.rs @@ -0,0 +1,14 @@ +use bitcoincore_rpc::{Auth, Client, RpcApi}; + +pub fn client() { + let rpc = Client::new( + "http://localhost:8332", + Auth::UserPass( + "".to_string(), + "".to_string(), + ), + ) + .unwrap(); + let best_block_hash = rpc.get_best_block_hash().unwrap(); + println!("best block hash: {}", best_block_hash); +} diff --git a/side-node/src/clients/mod.rs b/side-node/src/clients/mod.rs new file mode 100644 index 0000000..e0c6d71 --- /dev/null +++ b/side-node/src/clients/mod.rs @@ -0,0 +1,2 @@ +pub mod btc; +pub mod websocket; diff --git a/side-node/src/websocket.rs b/side-node/src/clients/websocket.rs similarity index 86% rename from side-node/src/websocket.rs rename to side-node/src/clients/websocket.rs index b3a1e05..f7bfde0 100644 --- a/side-node/src/websocket.rs +++ b/side-node/src/clients/websocket.rs @@ -5,19 +5,17 @@ use tokio::sync::mpsc; use crate::utils; -pub struct WebSocketClient { +pub struct Client { incoming_sender: mpsc::Sender, - handle: ezsockets::Client, + handle: ezsockets::Client, } -impl WebSocketClient { +impl Client { /// Start the websocket client - pub async fn new( - incoming_sender: mpsc::Sender, - ) -> ezsockets::Client { + pub async fn new(incoming_sender: mpsc::Sender) -> ezsockets::Client { let config = ClientConfig::new("ws://localhost:8080/websocket"); let (handle, future) = ezsockets::connect( - |client| WebSocketClient { + |client| Client { incoming_sender, handle: client, }, @@ -32,7 +30,7 @@ impl WebSocketClient { } #[async_trait] -impl ezsockets::ClientExt for WebSocketClient { +impl ezsockets::ClientExt for Client { // Right now we're only using the Call type for sending signed ops // change this to an enum if we need to send other types of calls, and // match on it. diff --git a/side-node/src/lib.rs b/side-node/src/lib.rs index 9400626..149b3de 100644 --- a/side-node/src/lib.rs +++ b/side-node/src/lib.rs @@ -1,18 +1,18 @@ use bft_json_crdt::json_crdt::{BaseCrdt, SignedOp}; use cli::{parse_args, Commands}; +use clients::websocket; use crdt::TransactionList; use node::SideNode; use tokio::{sync::mpsc, task}; -use websocket::WebSocketClient; pub(crate) mod cli; +pub mod clients; pub mod crdt; pub(crate) mod init; pub mod keys; pub mod node; pub(crate) mod stdin; pub mod utils; -pub mod websocket; #[tokio::main] pub async fn run() { @@ -30,6 +30,9 @@ pub async fn run() { let mut node = setup(name).await; node.start().await; } + Some(Commands::Btc {}) => { + println!("BTC command not yet implemented."); + } None => println!("No command provided. Exiting. See --help for more information."), } } @@ -50,7 +53,7 @@ async fn setup(name: &String) -> SideNode { }); // Finally, create the node and return it - let handle = WebSocketClient::new(incoming_sender).await; + let handle = websocket::Client::new(incoming_sender).await; let node = SideNode::new( crdt, bft_crdt_keys, diff --git a/side-node/src/node.rs b/side-node/src/node.rs index 19156a8..882b4a0 100644 --- a/side-node/src/node.rs +++ b/side-node/src/node.rs @@ -2,7 +2,7 @@ use bft_json_crdt::json_crdt::{BaseCrdt, SignedOp}; use fastcrypto::ed25519::Ed25519KeyPair; use tokio::sync::mpsc; -use crate::{crdt::TransactionList, utils, websocket::WebSocketClient}; +use crate::{clients::websocket::Client, crdt::TransactionList, utils}; pub struct SideNode { crdt: BaseCrdt, @@ -10,7 +10,7 @@ pub struct SideNode { bitcoin_keys: bitcoin::secp256k1::Keypair, incoming_receiver: mpsc::Receiver, stdin_receiver: std::sync::mpsc::Receiver, - handle: ezsockets::Client, + handle: ezsockets::Client, } impl SideNode { @@ -20,7 +20,7 @@ impl SideNode { bitcoin_keys: bitcoin::secp256k1::Keypair, incoming_receiver: mpsc::Receiver, stdin_receiver: std::sync::mpsc::Receiver, - handle: ezsockets::Client, + handle: ezsockets::Client, ) -> Self { let node = Self { crdt, diff --git a/side-node/tests/side_node.rs b/side-node/tests/side_node.rs index 355d7d6..951a1a9 100644 --- a/side-node/tests/side_node.rs +++ b/side-node/tests/side_node.rs @@ -2,7 +2,7 @@ use bft_json_crdt::{ json_crdt::{BaseCrdt, SignedOp}, keypair::make_keypair, }; -use side_node::{crdt::TransactionList, keys, node::SideNode, utils, websocket::WebSocketClient}; +use side_node::{clients::websocket::Client, crdt::TransactionList, keys, node::SideNode, utils}; use tokio::sync::mpsc; #[tokio::test] @@ -43,7 +43,7 @@ async fn setup(_: &str) -> SideNode { let (_, stdin_receiver) = std::sync::mpsc::channel(); // Finally, create the node and return it - let handle = WebSocketClient::new(incoming_sender).await; + let handle = Client::new(incoming_sender).await; let node = SideNode::new( crdt, bft_crdt_keys,