Skip to content

Commit

Permalink
chore: upgrade to hc 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrichard23 committed Jan 23, 2025
1 parent d54429d commit fc894a9
Show file tree
Hide file tree
Showing 25 changed files with 2,944 additions and 2,222 deletions.
1,876 changes: 190 additions & 1,686 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ members = ["dnas/*/zomes/coordinator/*", "dnas/*/zomes/integrity/*"]
resolver = "2"

[workspace.dependencies]
hdi = "0.4.2"
hdk = "0.3.2"
serde = "1.0"

tauri-plugin-holochain = { git = "https://github.com/darksoil-studio/p2p-shipyard", branch = "main" }
# time_indexing = { git = "https://github.com/ddd-mtl/time-indexing", branch = "hdk-3.0" }
# zome_utils = { git = "https://github.com/ddd-mtl/zome-utils", branch = "hdk-3.0" }
hdi = "=0.5.0"
hdk = "=0.4.0"
holochain_integrity_types = "=0.4.0"
serde = "=1.0.203"
# time_indexing = { git = "https://github.com/ddd-mtl/time-indexing", branch = "hdk-4.0-dev.20" }
# zome_utils = { git = "https://github.com/ddd-mtl/zome-utils", branch = "hdk-4.0" }

[workspace.dependencies.content]
path = "dnas/humm_earth_core/zomes/coordinator/content"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use content_integrity::*;
use hdi::hash_path::path::Component;
use hdk::prelude::*;
// use zome_utils::{get_eh, get_latest_typed_from_eh};
// use zome_utils::*;

use crate::{
Expand Down Expand Up @@ -158,16 +158,6 @@ pub fn get_record(dh: AnyDhtHash) -> ExternResult<Record> {
};
Ok(record)
}
pub fn record_to_eh(record: &Record) -> ExternResult<EntryHash> {
let maybe_eh = record.action().entry_hash();
if maybe_eh.is_none() {
warn!("record_to_eh(): entry_hash not found");
return Err(wasm_error!(WasmErrorInner::Guest(format!(
"record_to_eh(): entry_hash not found"
))));
}
Ok(maybe_eh.unwrap().clone())
}

pub type TypedEntryAndHash<T> = (T, ActionHash, EntryHash);
pub type OptionTypedEntryAndHash<T> = Option<TypedEntryAndHash<T>>;
Expand Down Expand Up @@ -275,9 +265,10 @@ pub fn list_by_dynamic_link(
Component::from(input.content_type),
Component::from(input.dynamic_link.clone()),
]);
let links = get_links(
GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::Dynamic)?.build(),
)?;

let get_links_input =
GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::Dynamic)?.build();
let links = get_links(get_links_input)?;
let hashes: Vec<ActionHash> = links
.into_iter()
.map(|link| link.target.into_action_hash())
Expand All @@ -298,10 +289,9 @@ pub fn list_by_hive_link(input: ListByHiveInput) -> ExternResult<Vec<EncryptedCo
Component::from(input.hive_id),
Component::from(input.content_type),
]);

let links = get_links(
GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::Hive)?.build(),
)?;
let get_links_input =
GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::Hive)?.build();
let links = get_links(get_links_input)?;
let hashes: Vec<ActionHash> = links
.into_iter()
.map(|link| link.target.into_action_hash())
Expand All @@ -324,10 +314,9 @@ pub fn get_by_content_id_link(
Component::from(input.hive_id.clone()),
Component::from(input.content_id.clone()),
]);

let links = get_links(
GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::HummContentId)?.build(),
)?;
let get_links_input =
GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::HummContentId)?.build();
let links = get_links(get_links_input)?;

let hashes: Vec<ActionHash> = links
.into_iter()
Expand Down Expand Up @@ -367,6 +356,7 @@ pub fn list_by_acl_link(input: ListByAclInput) -> ExternResult<Vec<EncryptedCont
Component::from(input.content_type),
Component::from(input.entity_id.clone()),
]);

let links = match input.acl_role.as_str() {
"Owner" => get_links(
GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::HummContentOwner)?
Expand Down Expand Up @@ -410,10 +400,10 @@ pub fn list_by_author(input: ListByAuthorInput) -> ExternResult<Vec<EncryptedCon
Component::from(input.author),
Component::from(input.content_type),
]);

let links = get_links(
GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::Hive)?.build(),
)?;

let hashes: Vec<ActionHash> = links
.into_iter()
.map(|link| link.target.into_action_hash())
Expand Down Expand Up @@ -444,6 +434,7 @@ pub fn update_encrypted_content(
)?
.build(),
)?;

if original_hash_link.is_empty() {
return Err(wasm_error!(WasmErrorInner::Guest(format!(
"Could not find the hash of the original EncryptedContent that is trying to be updated"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use content_integrity::{EncryptedContent, LinkTypes};
use hdi::hash_path::path::Component;
use hdk::prelude::*;

// TODO: use the public key acl instead of the entity acl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use content_integrity::{EncryptedContent, LinkTypes};
use hdi::hash_path::path::Component;
use hdk::prelude::*;

pub fn create_dynamic_links(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use content_integrity::{EncryptedContent, LinkTypes};
use hdi::hash_path::path::Component;
use hdk::prelude::*;

pub fn create_hive_link(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use content_integrity::{EncryptedContent, LinkTypes};
use hdi::hash_path::path::Component;
use hdk::prelude::*;

pub fn create_humm_content_id_link(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::vec;

use content_integrity::*;
use hdk::{hash_path::path::Component, prelude::*};
use hdk::prelude::*;
use hdi::hash_path::path::Component;
use time_indexing::*;

pub fn time_index_encrypted_content(ah: ActionHash, content_type: &str) -> ExternResult<TypedPath> {
let agent_info = agent_info()?;
let time = get(ah.clone(), GetOptions::content())?
let time = get(ah.clone(), GetOptions::default())?
.unwrap()
.action()
.timestamp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ pub fn validate_create_encrypted_content(
pub fn validate_update_encrypted_content(
_action: Update,
_encrypted_content: EncryptedContent,
_original_action: EntryCreationAction,
_original_encrypted_content: EncryptedContent,
) -> ExternResult<ValidateCallbackResult> {
Ok(ValidateCallbackResult::Valid)
}
Expand Down
63 changes: 28 additions & 35 deletions dnas/humm_earth_core/zomes/integrity/content/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use hdi::prelude::*;
#[derive(Serialize, Deserialize)]
#[serde(tag = "type")]
#[hdk_entry_types]
#[unit_enum(UnitEntryTypes)]
#[unit_enum(EntryTypesUnit)]
pub enum EntryTypes {
EncryptedContent(EncryptedContent),
}
Expand Down Expand Up @@ -70,6 +70,13 @@ pub fn validate(op: Op) -> ExternResult<ValidateCallbackResult> {
// "Original and updated entry types must be the same".to_string(),
// )),
// },
OpUpdate::Entry { app_entry, action } => match app_entry {
EntryTypes::EncryptedContent(encrypted_content) => {
validate_update_encrypted_content(action, encrypted_content)
} // _ => Ok(ValidateCallbackResult::Invalid(
// "Original and updated entry types must be the same".to_string(),
// )),
},
_ => Ok(ValidateCallbackResult::Valid),
},
// TODO
Expand Down Expand Up @@ -170,47 +177,33 @@ pub fn validate(op: Op) -> ExternResult<ValidateCallbackResult> {
action,
..
} => {
let original_record = must_get_valid_record(original_action_hash)?;
let original_action = original_record.action().clone();
let original_action = match original_action {
Action::Create(create) => EntryCreationAction::Create(create),
Action::Update(update) => EntryCreationAction::Update(update),
_ => {
return Ok(ValidateCallbackResult::Invalid(
"Original action for an update must be a Create or Update action"
.to_string(),
));
}
};
// let original_record = must_get_valid_record(original_action_hash)?;
// let original_action = original_record.action().clone();

match app_entry {
EntryTypes::EncryptedContent(encrypted_content) => {
let result = validate_create_encrypted_content(
EntryCreationAction::Update(action.clone()),
encrypted_content.clone(),
)?;
if let ValidateCallbackResult::Valid = result {
let original_encrypted_content: Option<EncryptedContent> =
original_record
.entry()
.to_app_option()
.map_err(|e| wasm_error!(e))?;
let original_encrypted_content = match original_encrypted_content {
Some(encrypted_content) => encrypted_content,
None => {
return Ok(
ValidateCallbackResult::Invalid(
"The updated entry type must be the same as the original entry type"
.to_string(),
),
);
}
};
validate_update_encrypted_content(
action,
encrypted_content,
original_action,
original_encrypted_content,
)
// let original_encrypted_content: Option<EncryptedContent> =
// original_record
// .entry()
// .to_app_option()
// .map_err(|e| wasm_error!(e))?;
// let original_encrypted_content = match original_encrypted_content {
// Some(encrypted_content) => encrypted_content,
// None => {
// return Ok(
// ValidateCallbackResult::Invalid(
// "The updated entry type must be the same as the original entry type"
// .to_string(),
// ),
// );
// }
// };
validate_update_encrypted_content(action, encrypted_content)
} else {
Ok(result)
}
Expand Down
Loading

0 comments on commit fc894a9

Please sign in to comment.