Something went wrong. Try again.
fork of hydrant
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667pub(crate) use super::v4::{Commit, RepoMetadata, RepoStatus};use crate::db::types::DidKey;use jacquard_common::CowStr;use jacquard_common::types::string::Handle;use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(bound(deserialize = "'i: 'de"))]pub(crate) struct RepoState<'i> { pub active: bool, pub status: RepoStatus, pub root: Option<Commit>, pub last_message_time: Option<i64>, pub last_identity_time: Option<i64>, pub last_account_time: Option<i64>, pub last_updated_at: i64, // unix timestamp #[serde(borrow)] pub signing_key: Option<DidKey<'i>>, #[serde(borrow)] pub pds: Option<CowStr<'i>>, pub handle: Option<Handle>,}
#[cfg(test)]mod tests { use super::*;
#[test] fn v7_persisted_schema_golden_fixture() { let state = RepoState { active: true, status: RepoStatus::Synced, root: None, last_message_time: Some(7), last_identity_time: Some(8), last_account_time: Some(9), last_updated_at: 42, signing_key: Some(DidKey(std::borrow::Cow::Borrowed(&[0xed, 1, 2, 3]))), pds: Some("https://pds.example".into()), handle: Some(Handle::new_static("alice.test").unwrap()), }; let encoded = rmp_serde::to_vec(&state).unwrap(); assert_eq!( hex::encode(&encoded), "9ac3a653796e636564c00708092ac404ed010203b368747470733a2f2f7064732e6578616d706c65aa616c6963652e74657374" );
let decoded: RepoState<'_> = rmp_serde::from_slice(&encoded).unwrap(); assert!(decoded.active); assert_eq!(decoded.status, RepoStatus::Synced); assert_eq!(decoded.last_message_time, Some(7)); assert_eq!(decoded.last_identity_time, Some(8)); assert_eq!(decoded.last_account_time, Some(9)); assert_eq!(decoded.last_updated_at, 42); assert!(decoded.root.is_none()); assert_eq!( decoded.signing_key.as_ref().map(|key| key.0.as_ref()), Some([0xed, 1, 2, 3].as_slice()) ); assert_eq!(decoded.pds.as_deref(), Some("https://pds.example")); assert_eq!( decoded.handle.as_ref().map(Handle::as_str), Some("alice.test") ); }}