From 9aaa88b6d220f05de017ce1575e6ca9dd007f5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillem=20C=C3=B3rdoba?= Date: Thu, 5 Oct 2023 23:32:04 +0200 Subject: [PATCH] Allow IDE completion in exercise 2 --- EXERCISES.md | 18 +++++++++++++++--- .../private_publication/Cargo.toml | 1 + .../private_publication/src/lib.rs | 12 ++++++------ flake.lock | 6 +++--- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/EXERCISES.md b/EXERCISES.md index f50cb74..af83616 100644 --- a/EXERCISES.md +++ b/EXERCISES.md @@ -155,7 +155,7 @@ Go into `dnas/lobby/coordinator_zomes/private_publication_lobby/src/lib.rs`: - Get the links from your public key of type `LinkTypes::AgentToMembraneProof`. - If there is some link, return the record that the target is pointing to. -Go into `dnas/lobby/integrity_zomes/private_publication/src/properties.rs`: +Go into `dnas/private_publication/integrity_zomes/private_publication/src/properties.rs`: 3. Add a `Properties` struct, with only a `progenitor` field of type `AgentPubKeyB64`. @@ -172,10 +172,22 @@ Go into `dnas/private_publication/integrity_zomes/private_publication/src/membra 4. Implement the membrane proof check to avoid unwanted agents coming into the DHT: - If the agent we are validating for is the progenitor, then the membrane proof check is valid. - - If not, serialize the membrane proof into a `Record`. + - If not, deserialize the membrane proof into a `Record`. + - You can use `let bytes: SerializedBytes = Arc::try_unwrap(membrane_proof).map_err(|err| wasm_error!(WasmErrorInner::Guest(format!("{:?}", err))))?;` to unwrap the `MembraneProof` type into `SerializedBytes`. + - You can use `let record = Record::try_from(bytes);` to deserialize a `SerializedBytes` into a `Record`. - Check that the author of the action in the record is the progenitor. - - Check that the signature in the Record is valid for the `record.action_hashed().content()` of the record. + - Check that the signature in the `Record` is valid for the `record.action_hashed().content()` of the record. - Deserialize the record's entry into a `PrivatePublicationMembraneProof`. + - In general, to extract an entry in the form of its rust struct from a record that contains it, you can use `ENTRY_TYPE::try_from(entry)`. For example, to convert a record from a `Comment` app struct: + ```rust + let maybe_entry: Option = record + .entry + .into_option(); + + let entry: Entry = maybe_entry.ok_or(wasm_error!(WasmErrorInner::Guest(String::from("This record doesn't include any entry"))))?; + + let comment = Comment::try_from(entry)?; + ``` - Check that the dna hash inside the `PrivatePublicationMembraneProof` is equal to the dna hash of the `private_publication` DNA. - Check that the agent we are checking the membrane for is the agent that is inside the `PrivatePublicationMembraneProof`. diff --git a/dnas/private_publication/integrity_zomes/private_publication/Cargo.toml b/dnas/private_publication/integrity_zomes/private_publication/Cargo.toml index 3a1e994..5792e49 100644 --- a/dnas/private_publication/integrity_zomes/private_publication/Cargo.toml +++ b/dnas/private_publication/integrity_zomes/private_publication/Cargo.toml @@ -17,4 +17,5 @@ private_publication_integrity = { git = "https://github.com/holochain-immersive/ [features] exercise = [] +exercise1 = ["exercise"] exercise2 = [] diff --git a/dnas/private_publication/integrity_zomes/private_publication/src/lib.rs b/dnas/private_publication/integrity_zomes/private_publication/src/lib.rs index cce7ddd..e2b9013 100644 --- a/dnas/private_publication/integrity_zomes/private_publication/src/lib.rs +++ b/dnas/private_publication/integrity_zomes/private_publication/src/lib.rs @@ -2,17 +2,17 @@ /** Don't change */ -#[cfg(feature = "exercise2")] +#[cfg(not(feature = "exercise"))] pub mod membrane; -#[cfg(feature = "exercise2")] +#[cfg(not(feature = "exercise"))] pub mod post; -#[cfg(feature = "exercise2")] +#[cfg(not(feature = "exercise"))] pub mod properties; -#[cfg(feature = "exercise2")] +#[cfg(not(feature = "exercise"))] pub mod publication_role; -#[cfg(feature = "exercise2")] +#[cfg(not(feature = "exercise"))] pub mod validation; -#[cfg(feature = "exercise2")] +#[cfg(not(feature = "exercise"))] pub use validation::*; #[cfg(not(feature = "exercise2"))] diff --git a/flake.lock b/flake.lock index 2668ccb..fe86646 100644 --- a/flake.lock +++ b/flake.lock @@ -444,11 +444,11 @@ }, "locked": { "dir": "versions/0_1", - "lastModified": 1696435881, - "narHash": "sha256-BEHA/L7djjvzgqG7XkFL6M4JndzsnvW4JXmWgpwvkjo=", + "lastModified": 1696520631, + "narHash": "sha256-3Pz9S0igHa4lxX2eiOCDFrE6ltg6NWhOsrgoBJ/BZzY=", "owner": "holochain", "repo": "holochain", - "rev": "5f128fc5b0ca266da6f0390c5228fc31ef39f738", + "rev": "530e44968de908b817fa76d99f905521ffda7cab", "type": "github" }, "original": {