Now serializing a fake transaction instead sending a character

This commit is contained in:
Dave Hrycyszyn
2024-05-29 22:20:35 +01:00
parent cc627f15c5
commit d956442b54
3 changed files with 11 additions and 24 deletions

18
Cargo.lock generated
View File

@@ -296,6 +296,7 @@ dependencies = [
"itertools 0.12.1", "itertools 0.12.1",
"rand 0.8.5", "rand 0.8.5",
"random_color", "random_color",
"serde",
"serde_json", "serde_json",
"sha2 0.10.8", "sha2 0.10.8",
] ]
@@ -1031,12 +1032,6 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "half"
version = "1.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403"
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.12.3" version = "0.12.3"
@@ -1953,16 +1948,6 @@ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]]
name = "serde_cbor"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5"
dependencies = [
"half",
"serde",
]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.203" version = "1.0.203"
@@ -2090,7 +2075,6 @@ dependencies = [
"bft-json-crdt", "bft-json-crdt",
"clap", "clap",
"serde", "serde",
"serde_cbor",
"serde_json", "serde_json",
"tokio", "tokio",
"websockets", "websockets",

View File

@@ -11,7 +11,7 @@ tokio = { version = "1.37.0", features = ["time"] }
websockets = "0.3.0" websockets = "0.3.0"
bft-json-crdt = { path = "../../bft-json-crdt" } bft-json-crdt = { path = "../../bft-json-crdt" }
bft-crdt-derive = { path = "../../bft-json-crdt/bft-crdt-derive" } bft-crdt-derive = { path = "../../bft-json-crdt/bft-crdt-derive" }
serde_cbor = "0.11.2" # serde_cbor = "0.11.2" # move to this once we need to pack things in CBOR
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.117" serde_json = "1.0.117"

View File

@@ -1,7 +1,7 @@
use bft_crdt_derive::add_crdt_fields; use bft_crdt_derive::add_crdt_fields;
use bft_json_crdt::{ use bft_json_crdt::{
json_crdt::{BaseCrdt, CrdtNode, IntoCrdtNode}, json_crdt::{BaseCrdt, CrdtNode, IntoCrdtNode},
keypair::make_keypair, keypair::{make_keypair, ED25519_PUBLIC_KEY_LENGTH},
list_crdt::ListCrdt, list_crdt::ListCrdt,
op::ROOT_ID, op::ROOT_ID,
}; };
@@ -42,24 +42,27 @@ fn every_two_seconds() -> time::Interval {
} }
#[add_crdt_fields] #[add_crdt_fields]
#[derive(Clone, CrdtNode)] #[derive(Clone, CrdtNode, Serialize, Deserialize)]
struct ListExample { struct ListExample {
list: ListCrdt<char>, // switch to Transaction as soon as char is working list: ListCrdt<Transaction>, // switch to Transaction as soon as char is working
} }
/// A fake Transaction struct we can use as a simulated payload /// A fake Transaction struct we can use as a simulated payload
#[derive(Serialize, Deserialize)] #[add_crdt_fields]
#[derive(Clone, CrdtNode, Serialize, Deserialize)]
struct Transaction { struct Transaction {
from: String, from: String,
to: String, to: String,
amount: u64, amount: f64,
} }
fn generate_transaction() -> serde_json::Result<String> { fn generate_transaction() -> serde_json::Result<String> {
let transaction = Transaction { let transaction = Transaction {
from: "Alice".to_string(), from: "Alice".to_string(),
to: "Bob".to_string(), to: "Bob".to_string(),
amount: 100, amount: 100.0,
path: vec![],
id: [0; ED25519_PUBLIC_KEY_LENGTH],
}; };
let json = serde_json::to_string(&transaction).unwrap(); let json = serde_json::to_string(&transaction).unwrap();