2024-06-07 18:42:28 +01:00
|
|
|
use bft_crdt_derive::add_crdt_fields;
|
|
|
|
|
use bft_json_crdt::{
|
|
|
|
|
json_crdt::{CrdtNode, IntoCrdtNode},
|
|
|
|
|
list_crdt::ListCrdt,
|
|
|
|
|
};
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
|
|
#[add_crdt_fields]
|
|
|
|
|
#[derive(Clone, CrdtNode, Serialize, Deserialize)]
|
|
|
|
|
pub(crate) struct TransactionList {
|
|
|
|
|
pub(crate) list: ListCrdt<Transaction>,
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-11 19:16:36 +01:00
|
|
|
impl TransactionList {
|
|
|
|
|
pub(crate) fn view_sha(&self) -> String {
|
|
|
|
|
sha256::digest(serde_json::to_string(&self.list.view()).unwrap().as_bytes()).to_string()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-07 18:42:28 +01:00
|
|
|
/// A fake Transaction struct we can use as a simulated payload
|
|
|
|
|
#[add_crdt_fields]
|
|
|
|
|
#[derive(Clone, CrdtNode, Serialize, Deserialize)]
|
|
|
|
|
pub(crate) struct Transaction {
|
|
|
|
|
from: String,
|
|
|
|
|
to: String,
|
|
|
|
|
amount: f64,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// impl TransactionList {
|
|
|
|
|
// fn create(&mut self, keys: &Ed25519KeyPair) -> bft_json_crdt::json_crdt::SignedOp {
|
|
|
|
|
// // generate a placeholder transaction
|
|
|
|
|
// let transaction = _fake_transaction(keys.public().to_string());
|
|
|
|
|
|
|
|
|
|
// // next job is to keep adding to this guy
|
|
|
|
|
// let last: &Op<Transaction>;
|
|
|
|
|
// last = self.list.ops.last().expect("couldn't find last op");
|
|
|
|
|
// let signed_op = self.list.insert(last.id, transaction.clone()).sign(&keys);
|
|
|
|
|
// signed_op
|
|
|
|
|
// }
|
|
|
|
|
// }
|