Files
bft-crdt-experiment/side-node/src/node.rs

50 lines
1.2 KiB
Rust
Raw Normal View History

use bft_json_crdt::json_crdt::BaseCrdt;
2024-06-07 17:35:38 +01:00
use fastcrypto::ed25519::Ed25519KeyPair;
2024-06-07 17:18:46 +01:00
use crate::{list_transaction_crdt::TransactionList, websocket::WebSocketClient};
pub(crate) struct SideNode {
crdt: BaseCrdt<TransactionList>,
2024-06-07 17:35:38 +01:00
keys: fastcrypto::ed25519::Ed25519KeyPair,
websocket_client: WebSocketClient,
}
impl SideNode {
2024-06-07 17:35:38 +01:00
pub(crate) fn new(
websocket_client: WebSocketClient,
crdt: BaseCrdt<TransactionList>,
keys: Ed25519KeyPair,
) -> Self {
Self {
crdt,
2024-06-07 17:35:38 +01:00
keys,
websocket_client,
}
}
pub(crate) async fn start(&mut self) {
self.websocket_client.start().await;
}
2024-06-07 17:35:38 +01:00
fn add_transaction_locally(
&mut self,
transaction: serde_json::Value,
) -> bft_json_crdt::json_crdt::SignedOp {
// let last: &Op<Transaction>;
let last = self
.crdt
.doc
.list
.ops
.last()
.expect("couldn't find last op");
let signed_op = self
.crdt
.doc
.list
.insert(last.id, transaction)
.sign(&self.keys);
signed_op
}
}