Serialization of SignedOp now works; adding to the CRDT doesn't

This commit is contained in:
Dave Hrycyszyn
2024-06-05 16:50:28 +01:00
parent 4eac2ccf19
commit c866774612
6 changed files with 75 additions and 15 deletions

View File

@@ -22,6 +22,7 @@ rand = "0.8.5"
random_color = "0.6.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.85"
serde_with = "3.8.1"
sha2 = "0.10.6"
[dev-dependencies]

View File

@@ -17,6 +17,8 @@ use fastcrypto::{
traits::{KeyPair, ToFromBytes},
// Verifier,
};
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, Bytes};
/// Anything that can be nested in a JSON CRDT
pub trait CrdtNode: CrdtNodeFromValue + Hashable + Clone {
@@ -106,15 +108,18 @@ pub struct BaseCrdt<T: CrdtNode> {
}
/// An [`Op<Value>`] with a few bits of extra metadata
#[derive(Clone)]
#[serde_as]
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct SignedOp {
// Note that this can be different from the author of the inner op as the inner op could have been created
// by a different person
author: AuthorId,
/// Signed hash using priv key of author. Effectively [`OpID`] Use this as the ID to figure out what has been delivered already
#[serde_as(as = "Bytes")]
pub signed_digest: SignedDigest,
pub inner: Op<JsonValue>,
/// List of causal dependencies
#[serde_as(as = "Vec<Bytes>")]
pub depends_on: Vec<SignedDigest>,
}
@@ -244,7 +249,7 @@ impl<T: CrdtNode + DebugView> BaseCrdt<T> {
}
/// An enum representing a JSON value
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum JsonValue {
Null,
Bool(bool),

View File

@@ -81,7 +81,7 @@ pub fn parse_field(path: Vec<PathSegment>) -> Option<String> {
}
/// Represents a single node in a CRDT
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct Op<T>
where
T: CrdtNode,