Implemented a blank Btc command
This commit is contained in:
@@ -17,6 +17,9 @@ pub(crate) struct Args {
|
|||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub(crate) enum Commands {
|
pub(crate) enum Commands {
|
||||||
|
/// Placeholder for future BTC commands
|
||||||
|
Btc {},
|
||||||
|
|
||||||
/// runs the Side Node
|
/// runs the Side Node
|
||||||
Run { name: String },
|
Run { name: String },
|
||||||
|
|
||||||
|
|||||||
14
side-node/src/clients/btc.rs
Normal file
14
side-node/src/clients/btc.rs
Normal 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);
|
||||||
|
}
|
||||||
2
side-node/src/clients/mod.rs
Normal file
2
side-node/src/clients/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod btc;
|
||||||
|
pub mod websocket;
|
||||||
@@ -5,19 +5,17 @@ use tokio::sync::mpsc;
|
|||||||
|
|
||||||
use crate::utils;
|
use crate::utils;
|
||||||
|
|
||||||
pub struct WebSocketClient {
|
pub struct Client {
|
||||||
incoming_sender: mpsc::Sender<SignedOp>,
|
incoming_sender: mpsc::Sender<SignedOp>,
|
||||||
handle: ezsockets::Client<WebSocketClient>,
|
handle: ezsockets::Client<Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WebSocketClient {
|
impl Client {
|
||||||
/// Start the websocket client
|
/// Start the websocket client
|
||||||
pub async fn new(
|
pub async fn new(incoming_sender: mpsc::Sender<SignedOp>) -> ezsockets::Client<Client> {
|
||||||
incoming_sender: mpsc::Sender<SignedOp>,
|
|
||||||
) -> ezsockets::Client<WebSocketClient> {
|
|
||||||
let config = ClientConfig::new("ws://localhost:8080/websocket");
|
let config = ClientConfig::new("ws://localhost:8080/websocket");
|
||||||
let (handle, future) = ezsockets::connect(
|
let (handle, future) = ezsockets::connect(
|
||||||
|client| WebSocketClient {
|
|client| Client {
|
||||||
incoming_sender,
|
incoming_sender,
|
||||||
handle: client,
|
handle: client,
|
||||||
},
|
},
|
||||||
@@ -32,7 +30,7 @@ impl WebSocketClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[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
|
// 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
|
// change this to an enum if we need to send other types of calls, and
|
||||||
// match on it.
|
// match on it.
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
use bft_json_crdt::json_crdt::{BaseCrdt, SignedOp};
|
use bft_json_crdt::json_crdt::{BaseCrdt, SignedOp};
|
||||||
use cli::{parse_args, Commands};
|
use cli::{parse_args, Commands};
|
||||||
|
use clients::websocket;
|
||||||
use crdt::TransactionList;
|
use crdt::TransactionList;
|
||||||
use node::SideNode;
|
use node::SideNode;
|
||||||
use tokio::{sync::mpsc, task};
|
use tokio::{sync::mpsc, task};
|
||||||
use websocket::WebSocketClient;
|
|
||||||
|
|
||||||
pub(crate) mod cli;
|
pub(crate) mod cli;
|
||||||
|
pub mod clients;
|
||||||
pub mod crdt;
|
pub mod crdt;
|
||||||
pub(crate) mod init;
|
pub(crate) mod init;
|
||||||
pub mod keys;
|
pub mod keys;
|
||||||
pub mod node;
|
pub mod node;
|
||||||
pub(crate) mod stdin;
|
pub(crate) mod stdin;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod websocket;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn run() {
|
pub async fn run() {
|
||||||
@@ -30,6 +30,9 @@ pub async fn run() {
|
|||||||
let mut node = setup(name).await;
|
let mut node = setup(name).await;
|
||||||
node.start().await;
|
node.start().await;
|
||||||
}
|
}
|
||||||
|
Some(Commands::Btc {}) => {
|
||||||
|
println!("BTC command not yet implemented.");
|
||||||
|
}
|
||||||
None => println!("No command provided. Exiting. See --help for more information."),
|
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
|
// 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(
|
let node = SideNode::new(
|
||||||
crdt,
|
crdt,
|
||||||
bft_crdt_keys,
|
bft_crdt_keys,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use bft_json_crdt::json_crdt::{BaseCrdt, SignedOp};
|
|||||||
use fastcrypto::ed25519::Ed25519KeyPair;
|
use fastcrypto::ed25519::Ed25519KeyPair;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
use crate::{crdt::TransactionList, utils, websocket::WebSocketClient};
|
use crate::{clients::websocket::Client, crdt::TransactionList, utils};
|
||||||
|
|
||||||
pub struct SideNode {
|
pub struct SideNode {
|
||||||
crdt: BaseCrdt<TransactionList>,
|
crdt: BaseCrdt<TransactionList>,
|
||||||
@@ -10,7 +10,7 @@ pub struct SideNode {
|
|||||||
bitcoin_keys: bitcoin::secp256k1::Keypair,
|
bitcoin_keys: bitcoin::secp256k1::Keypair,
|
||||||
incoming_receiver: mpsc::Receiver<SignedOp>,
|
incoming_receiver: mpsc::Receiver<SignedOp>,
|
||||||
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
||||||
handle: ezsockets::Client<WebSocketClient>,
|
handle: ezsockets::Client<Client>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SideNode {
|
impl SideNode {
|
||||||
@@ -20,7 +20,7 @@ impl SideNode {
|
|||||||
bitcoin_keys: bitcoin::secp256k1::Keypair,
|
bitcoin_keys: bitcoin::secp256k1::Keypair,
|
||||||
incoming_receiver: mpsc::Receiver<SignedOp>,
|
incoming_receiver: mpsc::Receiver<SignedOp>,
|
||||||
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
||||||
handle: ezsockets::Client<WebSocketClient>,
|
handle: ezsockets::Client<Client>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let node = Self {
|
let node = Self {
|
||||||
crdt,
|
crdt,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use bft_json_crdt::{
|
|||||||
json_crdt::{BaseCrdt, SignedOp},
|
json_crdt::{BaseCrdt, SignedOp},
|
||||||
keypair::make_keypair,
|
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;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
@@ -43,7 +43,7 @@ async fn setup(_: &str) -> SideNode {
|
|||||||
let (_, stdin_receiver) = std::sync::mpsc::channel();
|
let (_, stdin_receiver) = std::sync::mpsc::channel();
|
||||||
|
|
||||||
// Finally, create the node and return it
|
// 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(
|
let node = SideNode::new(
|
||||||
crdt,
|
crdt,
|
||||||
bft_crdt_keys,
|
bft_crdt_keys,
|
||||||
|
|||||||
Reference in New Issue
Block a user