// Integrityuse hdi::prelude::*;#[hdk_entry_helper]struct Comment { comment: String}#[hdk_entry_helper]// We only need a stringstruct Anchor(String);#[hdk_entry_defs]#[unit_enum(UnitEntryTypes)]enum EntryTypes { Comment(Comment), Anchor(Anchor),}#[hdk_link_types]enum LinkTypes { AnchorToComment,}
Coordinator
// Coordinatoruse hdk::prelude::*;#[hdk_extern]fn create_comment(comment: Comment) -> ExternResult<ActionHash> { let comment_action_hash = create_entry(EntryTypes::Comment(comment))?; let anchor = Anchor(String::from("all_comments")); // Create the anchor entry let _anchor_action_hash = create_entry(EntryTypes::Anchor(anchor))?; let anchor_entry_hash = hash_entry(anchor)?; // This hash is deterministic create_link( anchor_entry_hash, comment_action_hash, LinkTypes::AnchorToComment, () )?; Ok(comment_action_hash)}#[hdk_extern]fn get_all_comments_hashes(_: ()) -> ExternResult<Vec<ActionHash>> { let anchor = Anchor(String::from("all_comments")); // Must use the same string as the create function let anchor_hash = hash_entry(anchor)?; let links = get_links(anchor_hash, LinkTypes::AnchorToComment, None)?; // Get all the links created above let action_hashes: Vec<ActionHash> = links.into_iter() .map(|link| ActionHash::from(link.target)) .collect(); // Extract the action hash from the links Ok(action_hashes)}