Figured out what on_call is for
This commit is contained in:
@@ -9,6 +9,7 @@ pub(crate) struct SideNode {
|
||||
keys: fastcrypto::ed25519::Ed25519KeyPair,
|
||||
incoming_receiver: mpsc::Receiver<SignedOp>,
|
||||
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
||||
network_sender: mpsc::Sender<SignedOp>,
|
||||
}
|
||||
|
||||
impl SideNode {
|
||||
@@ -17,12 +18,14 @@ impl SideNode {
|
||||
keys: Ed25519KeyPair,
|
||||
incoming_receiver: mpsc::Receiver<SignedOp>,
|
||||
stdin_receiver: std::sync::mpsc::Receiver<String>,
|
||||
network_sender: mpsc::Sender<SignedOp>,
|
||||
) -> Self {
|
||||
let node = Self {
|
||||
crdt,
|
||||
keys,
|
||||
incoming_receiver,
|
||||
stdin_receiver,
|
||||
network_sender,
|
||||
};
|
||||
node
|
||||
}
|
||||
@@ -31,27 +34,28 @@ impl SideNode {
|
||||
println!("Starting node...");
|
||||
|
||||
loop {
|
||||
match self.stdin_receiver.recv() {
|
||||
match self.stdin_receiver.try_recv() {
|
||||
Ok(stdin) => {
|
||||
println!("Received stdin input: {:?}", stdin);
|
||||
let transaction = utils::fake_transaction(stdin);
|
||||
let json = serde_json::to_value(transaction).unwrap();
|
||||
let signed_op = self._add_transaction_local(json);
|
||||
self.send_to_network(signed_op);
|
||||
let signed_op = self.add_transaction_local(json);
|
||||
self.send_to_network(signed_op).await;
|
||||
}
|
||||
Err(_) => {}
|
||||
Err(_) => {} // ignore empty channel errors in this PoC
|
||||
}
|
||||
match self.incoming_receiver.try_recv() {
|
||||
Ok(incoming) => {
|
||||
self.handle_incoming(&incoming);
|
||||
}
|
||||
Err(_) => {}
|
||||
Err(_) => {} // ignore empty channel errors in this PoC
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn send_to_network(&self, signed_op: SignedOp) {
|
||||
async fn send_to_network(&self, signed_op: SignedOp) {
|
||||
println!("sending to network: {:?}", signed_op);
|
||||
self.network_sender.send(signed_op).await.unwrap();
|
||||
}
|
||||
|
||||
fn handle_incoming(&mut self, incoming: &SignedOp) {
|
||||
@@ -59,7 +63,7 @@ impl SideNode {
|
||||
self.crdt.apply(incoming.clone());
|
||||
}
|
||||
|
||||
pub(crate) fn _add_transaction_local(
|
||||
pub(crate) fn add_transaction_local(
|
||||
&mut self,
|
||||
transaction: serde_json::Value,
|
||||
) -> bft_json_crdt::json_crdt::SignedOp {
|
||||
|
||||
Reference in New Issue
Block a user