Fixed some warnings
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
io::Write,
|
||||
path::PathBuf,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use bft_json_crdt::keypair::{make_keypair, Ed25519KeyPair};
|
||||
@@ -13,12 +13,12 @@ pub(crate) fn write(key_path: &PathBuf) -> Result<(), std::io::Error> {
|
||||
|
||||
let mut file = File::create(key_path)?;
|
||||
let out = keys.encode_base64();
|
||||
file.write(out.as_bytes())?;
|
||||
file.write_all(out.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn load_from_file(side_dir: &PathBuf) -> Ed25519KeyPair {
|
||||
let key_path = crate::utils::side_paths(side_dir.clone()).0;
|
||||
pub(crate) fn load_from_file(side_dir: &Path) -> Ed25519KeyPair {
|
||||
let key_path = crate::utils::side_paths(side_dir.to_path_buf()).0;
|
||||
|
||||
let data = fs::read_to_string(key_path).expect("couldn't read bft-bft-crdt key file");
|
||||
println!("data: {:?}", data);
|
||||
|
||||
@@ -2,9 +2,7 @@ use clap::Parser;
|
||||
use clap::Subcommand;
|
||||
|
||||
pub(crate) fn parse_args() -> Args {
|
||||
let args = Args::parse();
|
||||
|
||||
args
|
||||
Args::parse()
|
||||
}
|
||||
|
||||
/// A P2P BFT info sharing node
|
||||
|
||||
@@ -33,7 +33,7 @@ pub async fn run() {
|
||||
}
|
||||
|
||||
/// Wire everything up outside the application so that we can test more easily later
|
||||
async fn setup(name: &String) -> SideNode {
|
||||
async fn setup(name: &str) -> SideNode {
|
||||
// First, load up the keys and create a bft-crdt node
|
||||
let home_dir = utils::home(name);
|
||||
let bft_crdt_keys = bft_crdt::keys::load_from_file(&home_dir);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use crdt_node;
|
||||
|
||||
fn main() {
|
||||
crdt_node::run();
|
||||
}
|
||||
|
||||
@@ -21,36 +21,29 @@ impl SideNode {
|
||||
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
||||
handle: ezsockets::Client<Client>,
|
||||
) -> Self {
|
||||
let node = Self {
|
||||
Self {
|
||||
crdt,
|
||||
bft_crdt_keys,
|
||||
incoming_receiver,
|
||||
stdin_receiver,
|
||||
handle,
|
||||
};
|
||||
node
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn start(&mut self) {
|
||||
println!("Starting node...");
|
||||
|
||||
loop {
|
||||
match self.stdin_receiver.try_recv() {
|
||||
Ok(stdin) => {
|
||||
let transaction = utils::fake_generic_transaction_json(stdin);
|
||||
let json = serde_json::to_value(transaction).unwrap();
|
||||
let signed_op = self.add_transaction_local(json);
|
||||
println!("STDIN: {}", utils::sha_op(signed_op.clone()));
|
||||
self.send_to_network(signed_op).await;
|
||||
}
|
||||
Err(_) => {} // ignore empty channel errors in this PoC
|
||||
if let Ok(stdin) = self.stdin_receiver.try_recv() {
|
||||
let transaction = utils::fake_generic_transaction_json(stdin);
|
||||
let json = serde_json::to_value(transaction).unwrap();
|
||||
let signed_op = self.add_transaction_local(json);
|
||||
println!("STDIN: {}", utils::sha_op(signed_op.clone()));
|
||||
self.send_to_network(signed_op).await;
|
||||
}
|
||||
match self.incoming_receiver.try_recv() {
|
||||
Ok(incoming) => {
|
||||
println!("INCOMING: {}", utils::sha_op(incoming.clone()));
|
||||
self.handle_incoming(incoming);
|
||||
}
|
||||
Err(_) => {} // ignore empty channel errors in this PoC
|
||||
if let Ok(incoming) = self.incoming_receiver.try_recv() {
|
||||
println!("INCOMING: {}", utils::sha_op(incoming.clone()));
|
||||
self.handle_incoming(incoming);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,14 +69,13 @@ impl SideNode {
|
||||
.ops
|
||||
.last()
|
||||
.expect("couldn't find last op");
|
||||
let signed_op = self
|
||||
.crdt
|
||||
|
||||
// self.trace_crdt();
|
||||
self.crdt
|
||||
.doc
|
||||
.list
|
||||
.insert(last.id, transaction)
|
||||
.sign(&self.bft_crdt_keys);
|
||||
// self.trace_crdt();
|
||||
signed_op
|
||||
.sign(&self.bft_crdt_keys)
|
||||
}
|
||||
|
||||
/// Print the current state of the CRDT, can be used to debug
|
||||
|
||||
@@ -43,12 +43,12 @@ async fn setup(_: &str) -> SideNode {
|
||||
|
||||
// Finally, create the node and return it
|
||||
let handle = websocket::Client::new(incoming_sender).await;
|
||||
let node = SideNode::new(
|
||||
|
||||
SideNode::new(
|
||||
crdt,
|
||||
bft_crdt_keys,
|
||||
incoming_receiver,
|
||||
stdin_receiver,
|
||||
handle,
|
||||
);
|
||||
node
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user