Skip to content

Commit

Permalink
bumped to hdk 0.0.142 and REMOVED B64 hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthme committed Jul 26, 2022
1 parent 3f6688c commit 39ebb32
Show file tree
Hide file tree
Showing 14 changed files with 737 additions and 244 deletions.
778 changes: 606 additions & 172 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"crates/zome",
"crates/coordinator",
"crates/integrity",
"crates/types",
]
resolver = "2"
Expand Down
15 changes: 8 additions & 7 deletions crates/zome/Cargo.toml → crates/coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@
authors = ["[email protected]", "[email protected]", "[email protected]"]
description = "MembraneInvitations zome for any Holochain app"
documentation = "https://holochain-open-dev.github.io/membrane_invitations"
edition = "2018"
edition = "2021"
homepage = "https://docs.rs/hc_zome_membrane_invitations"
license = "MIT"
name = "hc_zome_membrane_invitations"
name = "hc_zome_membrane_invitations_coordinator"
repository = "https://github.com/holochain-open-dev/membrane_invitations"
version = "0.0.1"

[lib]
crate-type = ["cdylib", "rlib"]
name = "hc_zome_membrane_invitations"
name = "hc_zome_membrane_invitations_coordinator"

[dependencies]
derive_more = "0"
serde = "1"

hc_zome_membrane_invitations_integrity = { path = "../integrity"}
hc_zome_membrane_invitations_types = {path = "../types"}
hdk = {version = "0.0.136", features = ["encoding"]}
hdk = {version = "0.0.142", features = ["encoding"]}

[dev-dependencies]
fixt = "0.0.11"
fixt = "0.0.13"
futures = {version = "0.3.1", default-features = false}
hdk = {version = "0.0.136", features = ["encoding", "test_utils"]}
holochain = {version = "0.0.143", default-features = false, features = ["test_utils"]}
hdk = {version = "0.0.142", features = ["encoding", "test_utils"]}
holochain = {version = "0.0.150", default-features = false, features = ["test_utils"]}
tokio = {version = "1.3", features = ["full"]}
2 changes: 1 addition & 1 deletion crates/zome/README.md → crates/coordinator/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# hc_zome_membrane_invitations

MembraneInvitations zome for any Holochain app.
MembraneInvitations coordinator zome for any Holochain app.

## Documentation

Expand Down
77 changes: 39 additions & 38 deletions crates/zome/src/lib.rs → crates/coordinator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use hdk::prelude::holo_hash::*;
use hdk::prelude::*;

use hc_zome_membrane_invitations_types::*;
use hc_zome_membrane_invitations_integrity::*;


entry_defs![CloneDnaRecipe::entry_def()];

#[hdk_extern]
fn init(_: ()) -> ExternResult<InitCallbackResult> {
Expand All @@ -24,34 +25,32 @@ fn init(_: ()) -> ExternResult<InitCallbackResult> {
Ok(InitCallbackResult::Pass)
}

#[hdk_extern]
fn recv_remote_signal(signal: ExternIO) -> ExternResult<()> {
let sig: Signal = signal.decode()?;
Ok(emit_signal(&sig)?)
}



#[hdk_extern]
pub fn create_clone_dna_recipe(clone_dna_recipe: CloneDnaRecipe) -> ExternResult<EntryHashB64> {
pub fn create_clone_dna_recipe(clone_dna_recipe: CloneDnaRecipe) -> ExternResult<EntryHash> {
let hash = hash_entry(&clone_dna_recipe)?;

create_entry(&clone_dna_recipe)?;
create_entry(EntryTypes::CloneDnaRecipe(clone_dna_recipe.clone()))?;

create_link(
DnaHash::from(clone_dna_recipe.original_dna_hash).retype(hash_type::Entry),
hash.clone(),
HdkLinkType::Any,
LinkTypes::DnaHashToRecipe,
(),
)?;

Ok(hash.into())
Ok(hash)
}

#[hdk_extern]
pub fn get_clone_recipes_for_dna(
original_dna_hash: DnaHashB64,
) -> ExternResult<BTreeMap<EntryHashB64, CloneDnaRecipe>> {
original_dna_hash: DnaHash,
) -> ExternResult<BTreeMap<EntryHash, CloneDnaRecipe>> {
let links = get_links(
DnaHash::from(original_dna_hash).retype(hash_type::Entry),
LinkTypes::DnaHashToRecipe,
None,
)?;

Expand All @@ -63,75 +62,79 @@ pub fn get_clone_recipes_for_dna(
#[serde(rename_all = "camelCase")]
pub enum Signal {
NewInvitation {
invitation_header_hash: HeaderHashB64,
invitation_action_hash: ActionHash,
invitation: JoinMembraneInvitation,
},
}

#[hdk_extern]
pub fn invite_to_join_membrane(input: InviteToJoinMembraneInput) -> ExternResult<HeaderHashB64> {
pub fn invite_to_join_membrane(input: InviteToJoinMembraneInput) -> ExternResult<ActionHash> {
let tag: LinkTag = match input.membrane_proof.clone() {
None => LinkTag::new(vec![]),
Some(mp) => LinkTag::new(mp.bytes().clone()),
};

let clone_dna_recipe_hash = hash_entry(&input.clone_dna_recipe)?;

let invitee_pub_key = AgentPubKey::from(input.invitee);
let invitee_pub_key = input.invitee;

let header_hash = create_link(
// create link from invitee to the clone dna recipe
let action_hash = create_link(
invitee_pub_key.clone(),
EntryHash::from(clone_dna_recipe_hash),
HdkLinkType::Any,
LinkTypes::InviteeToRecipe,
tag,
)?;

let invitation = JoinMembraneInvitation {
invitee: invitee_pub_key.clone().into(),
clone_dna_recipe: input.clone_dna_recipe,
inviter: agent_info()?.agent_initial_pubkey.into(),
inviter: agent_info()?.agent_initial_pubkey,
membrane_proof: input.membrane_proof,
timestamp: sys_time()?,
};

let signal = Signal::NewInvitation {
invitation,
invitation_header_hash: header_hash.clone().into(),
invitation_action_hash: action_hash.clone(),
};

remote_signal(ExternIO::encode(signal)?, vec![invitee_pub_key])?;
let encoded_signal = ExternIO::encode(signal)
.map_err(|err| wasm_error!(WasmErrorInner::Guest(err.into())))?;

remote_signal(encoded_signal, vec![invitee_pub_key])?;

Ok(header_hash.into())
Ok(action_hash)
}

#[hdk_extern]
pub fn get_my_invitations(_: ()) -> ExternResult<BTreeMap<HeaderHashB64, JoinMembraneInvitation>> {
pub fn get_my_invitations(_: ()) -> ExternResult<BTreeMap<ActionHash, JoinMembraneInvitation>> {
let agent_info = agent_info()?;

let links = get_links(agent_info.agent_initial_pubkey.clone(), None)?;
let links = get_links(agent_info.agent_initial_pubkey.clone(), LinkTypes::InviteeToRecipe, None)?;

let recipes = get_clone_dna_recipes(&links)?;

let mut my_invitations: BTreeMap<HeaderHashB64, JoinMembraneInvitation> = BTreeMap::new();
let mut my_invitations: BTreeMap<ActionHash, JoinMembraneInvitation> = BTreeMap::new();

for link in links {
if let Some(recipe) = recipes.get(&EntryHashB64::from(EntryHash::from(link.target))) {
if let Some(recipe) = recipes.get(&EntryHash::from(link.target)) {
let membrane_proof = match link.tag.0.len() > 0 {
true => Some(Arc::new(SerializedBytes::from(UnsafeBytes::from(link.tag.0)))),
false => None,
};

// Remove this get when the link struct includes author
if let Some(el) = get(link.create_link_hash.clone(), GetOptions::default())? {
if let Some(record) = get(link.create_link_hash.clone(), GetOptions::default())? {
let invitation = JoinMembraneInvitation {
clone_dna_recipe: recipe.clone(),
inviter: el.header().author().clone().into(),
invitee: agent_info.agent_initial_pubkey.clone().into(),
inviter: record.action().author().clone(),
invitee: agent_info.agent_initial_pubkey.clone(),
membrane_proof,
timestamp: link.timestamp,
};

my_invitations.insert(link.create_link_hash.into(), invitation);
my_invitations.insert(link.create_link_hash, invitation);
}
}
}
Expand All @@ -141,30 +144,28 @@ pub fn get_my_invitations(_: ()) -> ExternResult<BTreeMap<HeaderHashB64, JoinMem

fn get_clone_dna_recipes(
links: &Vec<Link>,
) -> ExternResult<BTreeMap<EntryHashB64, CloneDnaRecipe>> {
) -> ExternResult<BTreeMap<EntryHash, CloneDnaRecipe>> {
let get_inputs = links
.iter()
.map(|link| GetInput::new(link.target.clone().into(), GetOptions::default()))
.collect();

let elements = HDK.with(|hdk| hdk.borrow().get(get_inputs))?;

let clones: BTreeMap<EntryHashB64, CloneDnaRecipe> = elements
let clones: BTreeMap<EntryHash, CloneDnaRecipe> = elements
.into_iter()
.filter_map(|e| e)
.filter_map(|el| {
let recipe: Option<CloneDnaRecipe> = el.entry().to_app_option().unwrap_or(None);

recipe.map(|r| (el.header().entry_hash().unwrap().clone().into(), r))
.filter_map(|r| r)
.filter_map(|record| {
let recipe: Option<CloneDnaRecipe> = record.entry().to_app_option().unwrap_or(None);
recipe.map(|r| (record.action().entry_hash().unwrap().clone(), r))
})
.collect();

Ok(clones)
}

#[hdk_extern]
pub fn remove_invitation(invitation_link_hash: HeaderHashB64) -> ExternResult<()> {
pub fn remove_invitation(invitation_link_hash: ActionHash) -> ExternResult<()> {
delete_link(invitation_link_hash.into())?;

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ async fn main_flow() {
let alice_zome = alice.zome("membrane_invitations");
let bob_zome = bobbo.zome("membrane_invitations");

let original_dna_hash = fixt!(DnaHashB64);
let resulting_dna_hash = fixt!(DnaHashB64);
let original_dna_hash = fixt!(DnaHash);
let resulting_dna_hash = fixt!(DnaHash);

let create_clone_dna_recipe_input = CloneDnaRecipe {
original_dna_hash: original_dna_hash.clone(),
Expand Down Expand Up @@ -69,13 +69,13 @@ async fn main_flow() {
membrane_proof: Some(Arc::new(SerializedBytes::try_from(()).unwrap())),
};

let invitation_header_hash: HeaderHashB64 = conductors[0]
let invitation_header_hash: ActionHash = conductors[0]
.call(&alice_zome, "invite_to_join_membrane", invitation)
.await;

consistency_10s(&[&alice, &bobbo]).await;

let bobs_invitations: BTreeMap<HeaderHashB64, JoinMembraneInvitation> = conductors[1]
let bobs_invitations: BTreeMap<ActionHash, JoinMembraneInvitation> = conductors[1]
.call(&bob_zome, "get_my_invitations", ())
.await;

Expand Down
21 changes: 21 additions & 0 deletions crates/integrity/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
authors = ["[email protected]", "[email protected]", "[email protected]"]
description = "MembraneInvitations zome for any Holochain app"
documentation = "https://holochain-open-dev.github.io/membrane_invitations"
edition = "2021"
homepage = "https://docs.rs/hc_zome_membrane_invitations"
license = "MIT"
name = "hc_zome_membrane_invitations_integrity"
repository = "https://github.com/holochain-open-dev/membrane_invitations"
version = "0.0.1"

[lib]
crate-type = ["cdylib", "rlib"]
name = "hc_zome_membrane_invitations_integrity"

[dependencies]
derive_more = "0"
serde = "1"

hc_zome_membrane_invitations_types = {path = "../types"}
hdi = "0.0.14"
7 changes: 7 additions & 0 deletions crates/integrity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# hc_zome_membrane_invitations_integrity

MembraneInvitations integrity zome for any Holochain app.

## Documentation

See our [installation instructions and documentation](https://holochain-open-dev.github.io/membrane-invitations).
22 changes: 22 additions & 0 deletions crates/integrity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! ## hc_zome_membrane_invitations
use hdi::prelude::*;

use hc_zome_membrane_invitations_types::*;

#[hdk_entry_defs]
#[unit_enum(UnitEntryTypes)]
pub enum EntryTypes {
CloneDnaRecipe(CloneDnaRecipe),
}

#[hdk_link_types]
pub enum LinkTypes {
DnaHashToRecipe,
InviteeToRecipe,
}

#[hdk_extern]
pub fn validate(_op: Op) -> ExternResult<ValidateCallbackResult> {
Ok(ValidateCallbackResult::Valid)
}
4 changes: 2 additions & 2 deletions crates/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["[email protected]", "[email protected]", "[email protected]"]
description = "Types for the hc_zome_membrane_invitations zome"
documentation = "https://holochain-open-dev.github.io/membrane_invitations"
edition = "2018"
edition = "2021"
homepage = "https://docs.rs/hc_zome_membrane_invitations_types"
license = "MIT"
name = "hc_zome_membrane_invitations_types"
Expand All @@ -17,4 +17,4 @@ name = "hc_zome_membrane_invitations_types"
derive_more = "0"
serde = "1"

hdk = {version = "0.0.136", features = ["encoding"]}
hdi = "0.0.14"
18 changes: 8 additions & 10 deletions crates/types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
use hdk::prelude::holo_hash::*;
use hdk::prelude::*;
use hdi::prelude::holo_hash::*;
use hdi::prelude::*;

#[hdk_entry(id = "clone_dna_recipe")]
#[hdk_entry_helper]
#[serde(rename_all = "camelCase")]
#[derive(Clone)]
pub struct CloneDnaRecipe {
pub original_dna_hash: DnaHashB64,

pub original_dna_hash: DnaHash,
pub properties: SerializedBytes,
pub uid: Option<String>,

pub resulting_dna_hash: DnaHashB64,
pub resulting_dna_hash: DnaHash,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InviteToJoinMembraneInput {
pub clone_dna_recipe: CloneDnaRecipe,
pub invitee: AgentPubKeyB64,
pub invitee: AgentPubKey,
pub membrane_proof: Option<MembraneProof>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct JoinMembraneInvitation {
pub clone_dna_recipe: CloneDnaRecipe,
pub inviter: AgentPubKeyB64,
pub invitee: AgentPubKeyB64,
pub inviter: AgentPubKey,
pub invitee: AgentPubKey,
pub membrane_proof: Option<MembraneProof>,
pub timestamp: Timestamp,
}
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let
holonixPath = (import ./nix/sources.nix).holonix; # points to the current state of the Holochain repository
holonix = import (holonixPath) {
holochainVersionId = "v0_0_143"; # specifies the Holochain version
holochainVersionId = "v0_0_150"; # specifies the Holochain version
};
nixpkgs = holonix.pkgs;
in nixpkgs.mkShell {
Expand Down
Loading

0 comments on commit 39ebb32

Please sign in to comment.