Nearly there
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user