~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0
33 lines · 983 B Raw History
//! A space repo's commit (`com.atproto.space.defs#commit`), as
//! `spec/SPACES.md` ("The set hash, records and commits") defines it.

use pds_repo::data::V;

/// The commit's `ver`.
pub const VERSION: i64 = 1;

/// A space repo's commit, `ver` 1. It has no signature.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Commit {
    /// The author's DID.
    pub repo: String,
    /// The space's URI.
    pub space: String,
    /// A TID.
    pub rev: String,
    /// The LtHash digest of the elements of every record the repo holds.
    pub data: [u8; 32],
}

impl Commit {
    /// `{ver: 1, repo, space, rev, data}`, `data` as bytes.
    pub fn to_value(&self) -> V {
        V::Map(vec![
            ("ver".into(), V::Int(VERSION)),
            ("repo".into(), V::Str(self.repo.clone())),
            ("space".into(), V::Str(self.space.clone())),
            ("rev".into(), V::Str(self.rev.clone())),
            ("data".into(), V::Bytes(self.data.to_vec())),
        ])
    }
}