Resources Zome
Steps to create this zome:
-
Delete boilerplate zome
-
Define a
Resource
entry and add it to theentry_defs
#[hdk_entry(id = "resource")]
struct Resource {
owner_pub_key: AgentPubKey,
name: String,
}
entry_defs![Resource::entry_def()];
-
Add the
create_resource
function that:- Receives the name of the resource.
- Gets the public key of the executing agent with agent_info.
- Creates the resource with create_entry.
- Creates a link between the public key and the entry hash (using hash_entry and create_link).
-
Add the
get_my_resources
function that:- Gets the public key of the executing agent with agent_info.
- Does a get_links with the public key as the base.
- For each target hash, performs a get to get the contents of the
Resource
entry. - Returns the list of resources.
-
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: