Skip to content

Instantly share code, notes, and snippets.

@lucksus
Last active October 29, 2018 20:19
Show Gist options
  • Save lucksus/57f26743f9f56a940a67498e93413f7a to your computer and use it in GitHub Desktop.
Save lucksus/57f26743f9f56a940a67498e93413f7a to your computer and use it in GitHub Desktop.
#[derive(Serialize, Deserialize)]
pub struct Task {
text: String,
complete: bool,
}
define_zome! {
entries: [
entry!(
name: "task",
description: "a thing to do",
sharing: Sharing::Public,
native_type: Task,
validation_package: || {
hdk::ValidationPackageDefinition::Entry
},
validation: |task: Task, _ctx: hdk::ValidationData| {
(task.text.len() > 0)
.ok_or_else(|| String::from("Task text can't be empty"))
}
)
]
genesis: || {
Ok(())
}
functions: {
main (Public) {
create_task: {
inputs: |text: String|,
outputs: |address: serde_json::Value|,
handler: handle_create_task
}
list_tasks: {
inputs: | |,
outputs: |tasks: serde_json::Value|,
handler: handle_list_tasks
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment