From f140c6d28eb41454173c8a5d8685381afc3639fa Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Tue, 29 Nov 2022 23:53:29 +0100 Subject: [PATCH] cob: Add actor to `Entry` Signed-off-by: Alexis Sellier --- radicle-cob/src/change_graph/evaluation.rs | 1 + radicle-cob/src/history.rs | 5 +++++ radicle-cob/src/history/entry.rs | 15 +++++++++++++-- radicle-cob/src/object/collaboration/create.rs | 1 + radicle-cob/src/object/collaboration/update.rs | 16 ++++++++++------ radicle-cob/src/signatures.rs | 4 ++-- 6 files changed, 32 insertions(+), 10 deletions(-) diff --git a/radicle-cob/src/change_graph/evaluation.rs b/radicle-cob/src/change_graph/evaluation.rs index caf6a819..01bf915d 100644 --- a/radicle-cob/src/change_graph/evaluation.rs +++ b/radicle-cob/src/change_graph/evaluation.rs @@ -66,6 +66,7 @@ fn evaluate_change( Ok(history::Entry::new( *change.id(), + change.signature.key, *change.author(), change.resource, child_commits.iter().cloned(), diff --git a/radicle-cob/src/history.rs b/radicle-cob/src/history.rs index 9c83c515..09bb5d83 100644 --- a/radicle-cob/src/history.rs +++ b/radicle-cob/src/history.rs @@ -10,6 +10,7 @@ use std::{ use git_ext::Oid; use petgraph::visit::Walker as _; +use radicle_crypto::PublicKey; use crate::pruning_fold; @@ -50,6 +51,7 @@ pub enum CreateError { impl History { pub(crate) fn new_from_root( id: Id, + actor: PublicKey, author: Option, resource: Oid, contents: Contents, @@ -60,6 +62,7 @@ impl History { let id = id.into(); let root_entry = Entry { id, + actor, author, resource, children: vec![], @@ -126,6 +129,7 @@ impl History { pub(crate) fn extend( &mut self, new_id: Id, + new_actor: PublicKey, new_author: Option, new_resource: Oid, new_contents: Contents, @@ -136,6 +140,7 @@ impl History { let new_id = new_id.into(); let new_entry = Entry::new( new_id, + new_actor, new_author, new_resource, std::iter::empty::(), diff --git a/radicle-cob/src/history/entry.rs b/radicle-cob/src/history/entry.rs index 7fbc17be..c8e7e028 100644 --- a/radicle-cob/src/history/entry.rs +++ b/radicle-cob/src/history/entry.rs @@ -5,6 +5,8 @@ use git_ext::Oid; +use radicle_crypto::PublicKey; + use crate::pruning_fold; /// Entry contents. @@ -41,6 +43,8 @@ impl From for Oid { pub struct Entry { /// The identifier for this entry pub(super) id: EntryId, + /// The actor that authored this entry. + pub(super) actor: PublicKey, /// The content-address for this entry's author. /// TODO: This shouldn't be here? pub(super) author: Option, @@ -55,6 +59,7 @@ pub struct Entry { impl Entry { pub fn new( id: Id1, + actor: PublicKey, author: Option, resource: Oid, children: ChildIds, @@ -67,6 +72,7 @@ impl Entry { { Self { id: id.into(), + actor, author, resource, children: children.into_iter().map(|id| id.into()).collect(), @@ -84,9 +90,14 @@ impl Entry { self.resource } + /// The public key of the actor. + pub fn actor(&self) -> &PublicKey { + &self.actor + } + /// The `Oid` of the author that made this change. - pub fn author(&self) -> &Option { - &self.author + pub fn author(&self) -> Option<&Oid> { + self.author.as_ref() } /// The contents of this change diff --git a/radicle-cob/src/object/collaboration/create.rs b/radicle-cob/src/object/collaboration/create.rs index cabacfcc..052fb4a4 100644 --- a/radicle-cob/src/object/collaboration/create.rs +++ b/radicle-cob/src/object/collaboration/create.rs @@ -89,6 +89,7 @@ where let history = History::new_from_root( *init_change.id(), + init_change.signature.key, content, resource.content_id(), contents.clone(), diff --git a/radicle-cob/src/object/collaboration/update.rs b/radicle-cob/src/object/collaboration/update.rs index 5c098378..a8da328b 100644 --- a/radicle-cob/src/object/collaboration/update.rs +++ b/radicle-cob/src/object/collaboration/update.rs @@ -67,9 +67,10 @@ where message, } = args; - let content = match author { + let author = match author { None => None, Some(author) => { + // TODO: Remove? if !author.is_delegate(signer.public_key()) { return Err(error::Update::SignerIsNotAuthor); } else { @@ -87,7 +88,7 @@ where .ok_or(error::Update::NoSuchObject)?; let change = storage.create( - content, + author, resource.content_id(), signer, change::Create { @@ -98,10 +99,13 @@ where message, }, )?; - - object - .history - .extend(change.id, content, change.resource, changes); + object.history.extend( + change.id, + change.signature.key, + author, + change.resource, + changes, + ); storage .update(identifier, typename, &object_id, &change) .map_err(|err| error::Update::Refs { err: Box::new(err) })?; diff --git a/radicle-cob/src/signatures.rs b/radicle-cob/src/signatures.rs index 94a28493..746c28d6 100644 --- a/radicle-cob/src/signatures.rs +++ b/radicle-cob/src/signatures.rs @@ -20,8 +20,8 @@ pub mod error; #[derive(Clone, Debug, PartialEq, Eq)] pub struct Signature { - key: PublicKey, - sig: crypto::Signature, + pub(super) key: PublicKey, + pub(super) sig: crypto::Signature, } impl Signature {