Implemented a blank Btc command

This commit is contained in:
Dave Hrycyszyn
2024-06-20 17:21:41 +01:00
parent c0c5a12e84
commit 13e144f19e
7 changed files with 36 additions and 16 deletions

View File

@@ -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 },

View File

@@ -0,0 +1,14 @@
use bitcoincore_rpc::{Auth, Client, RpcApi};
pub fn client() {
let rpc = Client::new(
"http://localhost:8332",
Auth::UserPass(
"<FILL RPC USERNAME>".to_string(),
"<FILL RPC PASSWORD>".to_string(),
),
)
.unwrap();
let best_block_hash = rpc.get_best_block_hash().unwrap();
println!("best block hash: {}", best_block_hash);
}

View File

@@ -0,0 +1,2 @@
pub mod btc;
pub mod websocket;

View File

@@ -5,19 +5,17 @@ use tokio::sync::mpsc;
use crate::utils;
pub struct WebSocketClient {
pub struct Client {
incoming_sender: mpsc::Sender<SignedOp>,
handle: ezsockets::Client<WebSocketClient>,
handle: ezsockets::Client<Client>,
}
impl WebSocketClient {
impl Client {
/// Start the websocket client
pub async fn new(
incoming_sender: mpsc::Sender<SignedOp>,
) -> ezsockets::Client<WebSocketClient> {
pub async fn new(incoming_sender: mpsc::Sender<SignedOp>) -> ezsockets::Client<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.

View File

@@ -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,

View File

@@ -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<TransactionList>,
@@ -10,7 +10,7 @@ pub struct SideNode {
bitcoin_keys: bitcoin::secp256k1::Keypair,
incoming_receiver: mpsc::Receiver<SignedOp>,
stdin_receiver: std::sync::mpsc::Receiver<String>,
handle: ezsockets::Client<WebSocketClient>,
handle: ezsockets::Client<Client>,
}
impl SideNode {
@@ -20,7 +20,7 @@ impl SideNode {
bitcoin_keys: bitcoin::secp256k1::Keypair,
incoming_receiver: mpsc::Receiver<SignedOp>,
stdin_receiver: std::sync::mpsc::Receiver<String>,
handle: ezsockets::Client<WebSocketClient>,
handle: ezsockets::Client<Client>,
) -> Self {
let node = Self {
crdt,

View File

@@ -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,