cob: Add actor to `Entry`

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-11-29 23:53:29 +01:00
parent e83d47ff45
commit f140c6d28e
No known key found for this signature in database
6 changed files with 32 additions and 10 deletions

View File

@ -66,6 +66,7 @@ fn evaluate_change(
Ok(history::Entry::new( Ok(history::Entry::new(
*change.id(), *change.id(),
change.signature.key,
*change.author(), *change.author(),
change.resource, change.resource,
child_commits.iter().cloned(), child_commits.iter().cloned(),

View File

@ -10,6 +10,7 @@ use std::{
use git_ext::Oid; use git_ext::Oid;
use petgraph::visit::Walker as _; use petgraph::visit::Walker as _;
use radicle_crypto::PublicKey;
use crate::pruning_fold; use crate::pruning_fold;
@ -50,6 +51,7 @@ pub enum CreateError {
impl History { impl History {
pub(crate) fn new_from_root<Id>( pub(crate) fn new_from_root<Id>(
id: Id, id: Id,
actor: PublicKey,
author: Option<Oid>, author: Option<Oid>,
resource: Oid, resource: Oid,
contents: Contents, contents: Contents,
@ -60,6 +62,7 @@ impl History {
let id = id.into(); let id = id.into();
let root_entry = Entry { let root_entry = Entry {
id, id,
actor,
author, author,
resource, resource,
children: vec![], children: vec![],
@ -126,6 +129,7 @@ impl History {
pub(crate) fn extend<Id>( pub(crate) fn extend<Id>(
&mut self, &mut self,
new_id: Id, new_id: Id,
new_actor: PublicKey,
new_author: Option<Oid>, new_author: Option<Oid>,
new_resource: Oid, new_resource: Oid,
new_contents: Contents, new_contents: Contents,
@ -136,6 +140,7 @@ impl History {
let new_id = new_id.into(); let new_id = new_id.into();
let new_entry = Entry::new( let new_entry = Entry::new(
new_id, new_id,
new_actor,
new_author, new_author,
new_resource, new_resource,
std::iter::empty::<git2::Oid>(), std::iter::empty::<git2::Oid>(),

View File

@ -5,6 +5,8 @@
use git_ext::Oid; use git_ext::Oid;
use radicle_crypto::PublicKey;
use crate::pruning_fold; use crate::pruning_fold;
/// Entry contents. /// Entry contents.
@ -41,6 +43,8 @@ impl From<EntryId> for Oid {
pub struct Entry { pub struct Entry {
/// The identifier for this entry /// The identifier for this entry
pub(super) id: EntryId, pub(super) id: EntryId,
/// The actor that authored this entry.
pub(super) actor: PublicKey,
/// The content-address for this entry's author. /// The content-address for this entry's author.
/// TODO: This shouldn't be here? /// TODO: This shouldn't be here?
pub(super) author: Option<Oid>, pub(super) author: Option<Oid>,
@ -55,6 +59,7 @@ pub struct Entry {
impl Entry { impl Entry {
pub fn new<Id1, Id2, ChildIds>( pub fn new<Id1, Id2, ChildIds>(
id: Id1, id: Id1,
actor: PublicKey,
author: Option<Oid>, author: Option<Oid>,
resource: Oid, resource: Oid,
children: ChildIds, children: ChildIds,
@ -67,6 +72,7 @@ impl Entry {
{ {
Self { Self {
id: id.into(), id: id.into(),
actor,
author, author,
resource, resource,
children: children.into_iter().map(|id| id.into()).collect(), children: children.into_iter().map(|id| id.into()).collect(),
@ -84,9 +90,14 @@ impl Entry {
self.resource self.resource
} }
/// The public key of the actor.
pub fn actor(&self) -> &PublicKey {
&self.actor
}
/// The `Oid` of the author that made this change. /// The `Oid` of the author that made this change.
pub fn author(&self) -> &Option<Oid> { pub fn author(&self) -> Option<&Oid> {
&self.author self.author.as_ref()
} }
/// The contents of this change /// The contents of this change

View File

@ -89,6 +89,7 @@ where
let history = History::new_from_root( let history = History::new_from_root(
*init_change.id(), *init_change.id(),
init_change.signature.key,
content, content,
resource.content_id(), resource.content_id(),
contents.clone(), contents.clone(),

View File

@ -67,9 +67,10 @@ where
message, message,
} = args; } = args;
let content = match author { let author = match author {
None => None, None => None,
Some(author) => { Some(author) => {
// TODO: Remove?
if !author.is_delegate(signer.public_key()) { if !author.is_delegate(signer.public_key()) {
return Err(error::Update::SignerIsNotAuthor); return Err(error::Update::SignerIsNotAuthor);
} else { } else {
@ -87,7 +88,7 @@ where
.ok_or(error::Update::NoSuchObject)?; .ok_or(error::Update::NoSuchObject)?;
let change = storage.create( let change = storage.create(
content, author,
resource.content_id(), resource.content_id(),
signer, signer,
change::Create { change::Create {
@ -98,10 +99,13 @@ where
message, message,
}, },
)?; )?;
object.history.extend(
object change.id,
.history change.signature.key,
.extend(change.id, content, change.resource, changes); author,
change.resource,
changes,
);
storage storage
.update(identifier, typename, &object_id, &change) .update(identifier, typename, &object_id, &change)
.map_err(|err| error::Update::Refs { err: Box::new(err) })?; .map_err(|err| error::Update::Refs { err: Box::new(err) })?;

View File

@ -20,8 +20,8 @@ pub mod error;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Signature { pub struct Signature {
key: PublicKey, pub(super) key: PublicKey,
sig: crypto::Signature, pub(super) sig: crypto::Signature,
} }
impl Signature { impl Signature {