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

28 lines
696 B
Rust
Raw Normal View History

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 struct TransactionList {
pub list: ListCrdt<Transaction>,
2024-06-07 18:42:28 +01:00
}
2024-06-11 19:16:36 +01:00
impl TransactionList {
pub fn view_sha(&self) -> String {
2024-06-11 19:16:36 +01:00
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, PartialEq)]
pub struct Transaction {
2024-06-07 18:42:28 +01:00
from: String,
to: String,
amount: f64,
}