Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Various fixes to COBs
Alexis Sellier committed 3 years ago
commit 08811b4b875530f11186763a11cc23da855c9973
parent 80401f89ae078d0414afc48d7f45da8eec246329
7 files changed +44 -27
modified radicle-cob/src/object/collaboration/create.rs
@@ -48,19 +48,19 @@ impl<Author> Create<Author> {
///
/// The `args` are the metadata for this [`CollaborativeObject`]. See
/// [`Create`] for further information.
-
pub fn create<S, Signer, Author, Resource>(
+
pub fn create<S, G, Author, Resource>(
    storage: &S,
-
    signer: Signer,
+
    signer: &G,
    resource: &Resource,
    identifier: &S::Identifier,
    args: Create<Author>,
) -> Result<CollaborativeObject, error::Create>
where
    S: Store,
+
    G: crypto::Signer,
    Author: Identity,
    Author::Identifier: Clone + PartialEq,
    Resource: Identity,
-
    Signer: crypto::Signer,
{
    let Create {
        author,
@@ -81,7 +81,7 @@ where
    };

    let init_change = storage
-
        .create(content, resource.content_id(), &signer, args.create_spec())
+
        .create(content, resource.content_id(), signer, args.create_spec())
        .map_err(error::Create::from)?;

    let history = History::new_from_root(
modified radicle-cob/src/object/collaboration/update.rs
@@ -42,19 +42,19 @@ pub struct Update<Author> {
///
/// The `args` are the metadata for this [`CollaborativeObject`]
/// udpate. See [`Update`] for further information.
-
pub fn update<S, Signer, Resource, Author>(
+
pub fn update<S, G, Resource, Author>(
    storage: &S,
-
    signer: Signer,
+
    signer: &G,
    resource: &Resource,
    identifier: &S::Identifier,
    args: Update<Author>,
) -> Result<CollaborativeObject, error::Update>
where
    S: Store,
+
    G: crypto::Signer,
    Author: Identity,
    Author::Identifier: Clone + PartialEq,
    Resource: Identity,
-
    Signer: crypto::Signer,
{
    let Update {
        author,
@@ -86,7 +86,7 @@ where
    let change = storage.create(
        content,
        resource.content_id(),
-
        &signer,
+
        signer,
        change::Create {
            tips: object.tips().iter().cloned().collect(),
            contents: changes.clone(),
modified radicle-cob/src/tests.rs
@@ -22,7 +22,7 @@ fn roundtrip() {
    let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
    let cob = create(
        &storage,
-
        signer,
+
        &signer,
        &proj,
        &proj.identifier(),
        Create {
@@ -54,7 +54,7 @@ fn list_cobs() {
    let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
    let issue_1 = create(
        &storage,
-
        signer.clone(),
+
        &signer,
        &proj,
        &proj.identifier(),
        Create {
@@ -68,7 +68,7 @@ fn list_cobs() {

    let issue_2 = create(
        &storage,
-
        signer,
+
        &signer,
        &proj,
        &proj.identifier(),
        Create {
@@ -103,7 +103,7 @@ fn update_cob() {
    let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
    let cob = create(
        &storage,
-
        signer.clone(),
+
        &signer,
        &proj,
        &proj.identifier(),
        Create {
@@ -121,7 +121,7 @@ fn update_cob() {

    let updated = update(
        &storage,
-
        signer,
+
        &signer,
        &proj,
        &proj.identifier(),
        Update {
@@ -161,7 +161,7 @@ fn traverse_cobs() {
    let typename = "xyz.rad.issue".parse::<TypeName>().unwrap();
    let cob = create(
        &storage,
-
        terry_signer,
+
        &terry_signer,
        &terry_proj,
        &terry_proj.identifier(),
        Create {
@@ -183,7 +183,7 @@ fn traverse_cobs() {

    let updated = update(
        &storage,
-
        neil_signer,
+
        &neil_signer,
        &neil_proj,
        &neil_proj.identifier(),
        Update {
modified radicle/src/cob.rs
@@ -5,8 +5,11 @@ pub use cob::{
use radicle_cob as cob;
use radicle_git_ext::Oid;

+
pub use radicle_cob::*;
+

use crate::{
    identity::{project::Identity, Did},
+
    node::NodeId,
    storage::git::Repository,
};

@@ -21,6 +24,20 @@ pub struct Author {
    did: Did,
}

+
impl From<Did> for Author {
+
    fn from(did: Did) -> Self {
+
        Self { did }
+
    }
+
}
+

+
impl From<NodeId> for Author {
+
    fn from(node_id: NodeId) -> Self {
+
        Self {
+
            did: Did::from(node_id),
+
        }
+
    }
+
}
+

impl identity::Identity for Author {
    type Identifier = String;

@@ -47,14 +64,14 @@ impl identity::Identity for Author {
///
/// The `args` are the metadata for this [`CollaborativeObject`]
/// udpate. See [`Update`] for further information.
-
pub fn create<S>(
+
pub fn create<G>(
    repository: &Repository,
-
    signer: S,
+
    signer: &G,
    project: &Identity<Oid>,
    args: Create<Author>,
) -> Result<CollaborativeObject, error::Create>
where
-
    S: crypto::Signer,
+
    G: crypto::Signer,
{
    let namespace = *signer.public_key();
    cob::create(repository, signer, project, &namespace, args)
@@ -103,14 +120,14 @@ pub fn list(
///
/// The `args` are the metadata for this [`CollaborativeObject`]
/// udpate. See [`Update`] for further information.
-
pub fn update<S>(
+
pub fn update<G>(
    repository: &Repository,
-
    signer: S,
+
    signer: &G,
    project: &Identity<Oid>,
    args: Update<Author>,
) -> Result<CollaborativeObject, error::Update>
where
-
    S: crypto::Signer,
+
    G: crypto::Signer,
{
    let namespace = *signer.public_key();
    cob::update(repository, signer, project, &namespace, args)
modified radicle/src/git.rs
@@ -151,9 +151,9 @@ pub mod refs {
            let (_refs, _cobs, typename, mut object_id) = cob.non_empty_components();
            let object_id = object_id
                .next()
-
                .and_then(|oid| oid.parse::<cob::ObjectId>().ok())?;
+
                .and_then(|oid| oid.parse::<git2::Oid>().ok())?;
            let typename = typename.parse::<cob::TypeName>().ok()?;
-
            Some((typename, object_id))
+
            Some((typename, object_id.into()))
        }
    }

modified radicle/src/lib.rs
@@ -25,9 +25,9 @@ pub use storage::git::Storage;
pub mod prelude {
    use super::*;

-
    pub use crypto::{Signer, Verified};
-
    pub use identity::{Doc, Id};
+
    pub use crypto::{PublicKey, Signer, Verified};
+
    pub use identity::{Did, Doc, Id};
    pub use node::NodeId;
    pub use profile::Profile;
-
    pub use storage::BranchName;
+
    pub use storage::{BranchName, ReadRepository, ReadStorage, WriteRepository, WriteStorage};
}
modified radicle/src/storage/git.rs
@@ -771,7 +771,7 @@ impl cob::object::Storage for Repository {
        self.backend.reference(
            git::refs::storage::cob(identifier, typename, object_id).as_str(),
            (*change.id()).into(),
-
            false,
+
            true,
            &format!(
                "Updating collaborative object '{}/{}' with new change {}",
                typename,