Gym A gym tool Holochain Dev Workshops Playground Toggle darkmode

Resources Zome

Steps to create this zome:

  1. Delete boilerplate zome

  2. Define a Resource entry and add it to the entry_defs

#[hdk_entry(id = "resource")]
struct Resource {
    owner_pub_key: AgentPubKey,
    name: String,
}

entry_defs![Resource::entry_def()];
  1. Add the create_resource function that:

    1. Receives the name of the resource.
    2. Gets the public key of the executing agent with agent_info.
    3. Creates the resource with create_entry.
    4. Creates a link between the public key and the entry hash (using hash_entry and create_link).
  2. Add the get_my_resources function that:

    1. Gets the public key of the executing agent with agent_info.
    2. Does a get_links with the public key as the base.
    3. For each target hash, performs a get to get the contents of the Resource entry.
    4. Returns the list of resources.
  3. Add the validation functions for the links and the resources:

#[hdk_extern]
fn validate_create_entry_resource(data: ValidationData) -> ExternResult<ValidationCallbackResult> {
    ...
}

#[hdk_extern]
fn validate_link(data: ValidationData) -> ExternResult<ValidationCallbackResult> {
    ...
}

Gym Exercises

Not understanding something? You can look at this gym exercises to play a bit with the concepts: