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

49 lines
1.1 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 18:42:28 +01:00
use crate::{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
2024-06-07 18:42:28 +01:00
fn add_transaction_local(
2024-06-07 17:35:38 +01:00
&mut self,
transaction: serde_json::Value,
) -> bft_json_crdt::json_crdt::SignedOp {
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
}
}