Nearly there

This commit is contained in:
Dave Hrycyszyn
2024-06-07 17:35:38 +01:00
parent d91a631fdc
commit 5d6a1e806a
3 changed files with 34 additions and 5 deletions

View File

@@ -1,16 +1,23 @@
use bft_json_crdt::json_crdt::BaseCrdt;
use fastcrypto::ed25519::Ed25519KeyPair;
use crate::{list_transaction_crdt::TransactionList, websocket::WebSocketClient};
pub(crate) struct SideNode {
crdt: BaseCrdt<TransactionList>,
keys: fastcrypto::ed25519::Ed25519KeyPair,
websocket_client: WebSocketClient,
}
impl SideNode {
pub(crate) fn new(websocket_client: WebSocketClient, crdt: BaseCrdt<TransactionList>) -> Self {
pub(crate) fn new(
websocket_client: WebSocketClient,
crdt: BaseCrdt<TransactionList>,
keys: Ed25519KeyPair,
) -> Self {
Self {
crdt,
keys,
websocket_client,
}
}
@@ -18,4 +25,25 @@ impl SideNode {
pub(crate) async fn start(&mut self) {
self.websocket_client.start().await;
}
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
}
}