├── zome.json └── code ├── Cargo.toml ├── .hcbuild └── src └── lib.rs /zome.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "{{ name }}", 3 | "description": "Generated from the rust-zome-template" 4 | } 5 | -------------------------------------------------------------------------------- /code/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "{{ name }}" 3 | version = "0.1.0" 4 | authors = ["{{ author }}"] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | serde = "1.0" 9 | serde_json = { version = "1.0", features = ["preserve_order"] } 10 | serde_derive = "1.0" 11 | hdk = "={{ version }}" 12 | holochain_wasm_utils = "={{ version }}" 13 | holochain_json_derive = "0.0" 14 | 15 | [lib] 16 | path = "src/lib.rs" 17 | crate-type = ["cdylib"] 18 | -------------------------------------------------------------------------------- /code/.hcbuild: -------------------------------------------------------------------------------- 1 | { 2 | "steps": [ 3 | { 4 | "command": "CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && echo $CARGO_TARGET_DIR", 5 | "arguments": [] 6 | }, 7 | { 8 | "command": "CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && cargo", 9 | "arguments": [ 10 | "build", 11 | "--release", 12 | "--target=wasm32-unknown-unknown", 13 | "--target-dir=$CARGO_TARGET_DIR" 14 | ] 15 | }, 16 | { 17 | "command": "CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && wasm-gc", 18 | "arguments": ["$CARGO_TARGET_DIR/wasm32-unknown-unknown/release/{{ name }}.wasm"] 19 | }, 20 | { 21 | "command": "CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && wasm-opt", 22 | "arguments": [ 23 | "-Oz", 24 | "--vacuum", 25 | "$CARGO_TARGET_DIR/wasm32-unknown-unknown/release/{{ name }}.wasm" 26 | ] 27 | }, 28 | { 29 | "command": "CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && wasm2wat", 30 | "arguments": [ 31 | "$CARGO_TARGET_DIR/wasm32-unknown-unknown/release/{{ name }}.wasm", 32 | "-o", 33 | "$CARGO_TARGET_DIR/wasm32-unknown-unknown/release/{{ name }}.wat" 34 | ] 35 | }, 36 | { 37 | "command": "CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-/tmp/my_first_app/target} && wat2wasm", 38 | "arguments": [ 39 | "$CARGO_TARGET_DIR/wasm32-unknown-unknown/release/{{ name }}.wat", 40 | "-o", 41 | "$CARGO_TARGET_DIR/wasm32-unknown-unknown/release/{{ name }}.wasm" 42 | ] 43 | } 44 | ], 45 | "artifact": "${CARGO_TARGET_DIR:-/tmp/my_first_app/target}/wasm32-unknown-unknown/release/{{ name }}.wasm" 46 | } 47 | -------------------------------------------------------------------------------- /code/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate hdk; 3 | extern crate serde; 4 | #[macro_use] 5 | extern crate serde_derive; 6 | extern crate serde_json; 7 | #[macro_use] 8 | extern crate holochain_json_derive; 9 | 10 | use hdk::{ 11 | entry_definition::ValidatingEntryType, 12 | error::ZomeApiResult, 13 | }; 14 | use hdk::holochain_core_types::{ 15 | entry::Entry, 16 | dna::entry_types::Sharing, 17 | }; 18 | 19 | use hdk::holochain_persistence_api::{ 20 | cas::content::Address, 21 | }; 22 | 23 | use hdk::holochain_json_api::{ 24 | error::JsonError, 25 | json::JsonString, 26 | }; 27 | 28 | 29 | // see https://developer.holochain.org/api/{{ version }}/hdk/ for info on using the hdk library 30 | 31 | // This is a sample zome that defines an entry type "MyEntry" that can be committed to the 32 | // agent's chain via the exposed function create_my_entry 33 | 34 | #[derive(Serialize, Deserialize, Debug, DefaultJson,Clone)] 35 | pub struct MyEntry { 36 | content: String, 37 | } 38 | 39 | pub fn handle_create_my_entry(entry: MyEntry) -> ZomeApiResult
{ 40 | let entry = Entry::App("my_entry".into(), entry.into()); 41 | let address = hdk::commit_entry(&entry)?; 42 | Ok(address) 43 | } 44 | 45 | pub fn handle_get_my_entry(address: Address) -> ZomeApiResult