Giving nodes the ability to send transactions in a more controlled fashion

This commit is contained in:
Dave Hrycyszyn
2024-06-06 19:50:24 +01:00
parent 3f4b4324e5
commit 95e3127903
2 changed files with 15 additions and 29 deletions

View File

@@ -35,14 +35,12 @@ pub(crate) fn new(side_dir: PathBuf) -> (BaseCrdt<CrdtList>, Ed25519KeyPair) {
(bft_crdt, keys) (bft_crdt, keys)
} }
pub(crate) async fn send( pub(crate) fn send(
count: u32,
bft_crdt: &mut BaseCrdt<CrdtList>, bft_crdt: &mut BaseCrdt<CrdtList>,
// ws: &mut WebSocket,
keys: &Ed25519KeyPair, keys: &Ed25519KeyPair,
) { ) -> bft_json_crdt::json_crdt::SignedOp {
// generate a placeholder transaction // generate a placeholder transaction
let transaction = generate_transaction(count, keys.public().to_string()); let transaction = generate_transaction(keys.public().to_string());
// next job is to keep adding to this guy // next job is to keep adding to this guy
let next = bft_crdt.doc.list.ops.len(); let next = bft_crdt.doc.list.ops.len();
@@ -51,16 +49,13 @@ pub(crate) async fn send(
.list .list
.insert_idx(next - 1, transaction.clone()) .insert_idx(next - 1, transaction.clone())
.sign(&keys); .sign(&keys);
signed_op
// Ok(ws
// .send_text(serde_json::to_string(&signed_op).unwrap())
// .await?)
} }
fn generate_transaction(count: u32, pubkey: String) -> Value { fn generate_transaction(pubkey: String) -> Value {
json!({ json!({
"from": pubkey, "from": pubkey,
"to": "Bob", "to": "Bob",
"amount": count "amount": 1
}) })
} }

View File

@@ -1,23 +1,8 @@
/* /*
loop { loop {
let _ = list_transaction_crdt::send(count, bft_crdt, &mut ws, &keys).await;
let msg = ws.receive().await?;
// deserialize the received websocket Frame into a string
let msg = msg.into_text().unwrap().0;
// deserialize the message into a Transaction struct
let incoming_operation: SignedOp = serde_json::from_str(&msg).unwrap();
let author = general_purpose::STANDARD.encode(&incoming_operation.author()); let author = general_purpose::STANDARD.encode(&incoming_operation.author());
println!("Received from {:?}", author);
bft_crdt.apply(incoming_operation.clone()); bft_crdt.apply(incoming_operation.clone());
count = count + 1;
interval.tick().await;
} }
*/ */
@@ -28,7 +13,7 @@ use ezsockets::ClientConfig;
use fastcrypto::ed25519::Ed25519KeyPair; use fastcrypto::ed25519::Ed25519KeyPair;
use std::io::BufRead; use std::io::BufRead;
use crate::list_transaction_crdt::CrdtList; use crate::list_transaction_crdt::{self, CrdtList};
struct Client {} struct Client {}
@@ -63,7 +48,13 @@ pub(crate) async fn start(keys: Ed25519KeyPair, bft_crdt: &mut BaseCrdt<CrdtList
let lines = stdin.lock().lines(); let lines = stdin.lock().lines();
for line in lines { for line in lines {
let line = line.unwrap(); let line = line.unwrap();
tracing::info!("sending {line}"); let signed_op = if let "exit" = line.as_str() {
handle.text(line).unwrap(); break;
} else {
let op = list_transaction_crdt::send(bft_crdt, &keys);
op.to_string()
};
tracing::info!("sending {:?}", signed_op);
handle.text(signed_op).unwrap();
} }
} }