Moved all the bft_crdt stuff into its own module

This commit is contained in:
Dave Hrycyszyn
2024-06-25 13:50:02 +01:00
parent 7fb4585deb
commit e6a4fe0fd6
12 changed files with 23 additions and 23 deletions

View File

@@ -20,7 +20,7 @@ pub(crate) fn write(key_path: &PathBuf) -> Result<(), std::io::Error> {
pub(crate) fn load_from_file(side_dir: &PathBuf) -> Ed25519KeyPair {
let key_path = crate::utils::side_paths(side_dir.clone()).0;
let data = fs::read_to_string(key_path).expect("couldn't read bft-crdt key file");
let data = fs::read_to_string(key_path).expect("couldn't read bft-bft-crdt key file");
println!("data: {:?}", data);
Ed25519KeyPair::decode_base64(&data).expect("couldn't load keypair from file")

View File

@@ -5,6 +5,8 @@ use bft_json_crdt::{
};
use serde::{Deserialize, Serialize};
pub mod keys;
#[add_crdt_fields]
#[derive(Clone, CrdtNode, Serialize, Deserialize)]
pub struct TransactionList {

View File

@@ -36,8 +36,8 @@ impl ezsockets::ClientExt for Client {
// match on it.
type Call = String;
/// When we receive a text message, apply the crdt operation contained in it to our
/// local crdt.
/// When we receive a text message, apply the bft-crdt operation contained in it to our
/// local bft-crdt.
async fn on_text(&mut self, text: String) -> Result<(), ezsockets::Error> {
let string_sha = utils::shassy(text.clone());
println!("received text, sha: {string_sha}");
@@ -45,7 +45,7 @@ impl ezsockets::ClientExt for Client {
let object_sha = utils::shappy(incoming.clone());
println!("deserialized: {}", object_sha);
if string_sha != object_sha {
panic!("sha mismatch: {string_sha} != {object_sha}, bft-crdt has failed");
panic!("sha mismatch: {string_sha} != {object_sha}, bft-bft-crdt has failed");
}
self.incoming_sender.send(incoming).await?;
Ok(())

View File

@@ -2,7 +2,7 @@ use std::path::PathBuf;
use config::SideNodeConfig;
use crate::{bitcoin, keys, utils};
use crate::{bft_crdt, bitcoin, utils};
pub(crate) mod config;
@@ -10,8 +10,8 @@ pub(crate) fn init(home: PathBuf, config: SideNodeConfig) -> Result<(), std::io:
ensure_side_directory_exists(&home)?;
let (bft_crdt_key_path, bitcoin_key_path, config_path) = utils::side_paths(home.clone());
println!("Writing bft crdt key to: {:?}", bft_crdt_key_path);
keys::bft_crdt::write(&bft_crdt_key_path)?;
println!("Writing bft bft-crdt key to: {:?}", bft_crdt_key_path);
bft_crdt::keys::write(&bft_crdt_key_path)?;
println!("Writing bitcoin key to: {:?}", bitcoin_key_path);
bitcoin::keys::write(&bitcoin_key_path)?;

View File

@@ -1 +0,0 @@
pub mod bft_crdt;

View File

@@ -1,16 +1,15 @@
use bft_crdt::TransactionList;
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};
pub mod bft_crdt;
pub mod bitcoin;
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;
@@ -40,9 +39,9 @@ pub async fn run() {
/// Wire everything up outside the application so that we can test more easily later
async fn setup(name: &String) -> SideNode {
// First, load up the keys and create a bft-crdt
// First, load up the keys and create a bft-bft-crdt
let side_dir = utils::home(name);
let bft_crdt_keys = keys::bft_crdt::load_from_file(&side_dir);
let bft_crdt_keys = bft_crdt::keys::load_from_file(&side_dir);
let keys = bitcoin::keys::load_from_file(&side_dir).unwrap();
let bitcoin_wallet = bitcoin::clients::electrum::create_wallet(keys).unwrap();
let crdt = BaseCrdt::<TransactionList>::new(&bft_crdt_keys);

View File

@@ -3,7 +3,7 @@ use bft_json_crdt::json_crdt::{BaseCrdt, SignedOp};
use fastcrypto::ed25519::Ed25519KeyPair;
use tokio::sync::mpsc;
use crate::{clients::websocket::Client, crdt::TransactionList, utils};
use crate::{bft_crdt::TransactionList, clients::websocket::Client, utils};
pub struct SideNode {
crdt: BaseCrdt<TransactionList>,