Sure. It’s pretty much the default app generated by hc generate zomes/myentry
, so here’s the folder structure:
For the validate_agent() function I tried both with only returning Ok(())
and with the example given in the docs page you sent me.
And then here’s the content of the key files:
lib.rs
#[macro_use]
extern crate hdk;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
#[macro_use]
extern crate holochain_json_derive;
use hdk::{
entry_definition::ValidatingEntryType,
error::ZomeApiResult,
EntryValidationData,
};
use hdk::holochain_core_types::{
entry::Entry,
dna::entry_types::Sharing,
agent::AgentId,
};
use hdk::holochain_persistence_api::{
cas::content::Address,
};
use hdk::holochain_json_api::{
error::JsonError,
json::JsonString,
};
// see https://developer.holochain.org/api/0.0.25-alpha1/hdk/ for info on using the hdk library
// This is a sample zome that defines an entry type "MyEntry" that can be committed to the
// agent's chain via the exposed function create_my_entry
#[derive(Serialize, Deserialize, Debug, DefaultJson,Clone)]
pub struct MyEntry {
content: String,
}
pub fn handle_create_my_entry(entry: MyEntry) -> ZomeApiResult<Address> {
let entry = Entry::App("my_entry".into(), entry.into());
let address = hdk::commit_entry(&entry)?;
Ok(address)
}
pub fn handle_get_my_entry(address: Address) -> ZomeApiResult<Option<Entry>> {
hdk::get_entry(&address)
}
fn definition() -> ValidatingEntryType {
entry!(
name: "my_entry",
description: "this is a same entry defintion",
sharing: Sharing::Public,
validation_package: || {
hdk::ValidationPackageDefinition::Entry
},
validation: | _validation_data: hdk::EntryValidationData<MyEntry>| {
Ok(())
}
)
}
define_zome! {
entries: [
definition()
]
init: || { Ok(()) }
validate_agent: |validation_data : EntryValidationData::<AgentId>| {{
if let EntryValidationData::Create{entry, ..} = validation_data {
let agent = entry as AgentId;
if agent.nick == "reject_agent::app" {
Err("This agent will always be rejected".into())
} else {
Ok(())
}
} else {
Err("Cannot update or delete an agent at this time".into())
}
}}
functions: [
create_my_entry: {
inputs: |entry: MyEntry|,
outputs: |result: ZomeApiResult<Address>|,
handler: handle_create_my_entry
}
get_my_entry: {
inputs: |address: Address|,
outputs: |result: ZomeApiResult<Option<Entry>>|,
handler: handle_get_my_entry
}
]
traits: {
hc_public [create_my_entry,get_my_entry]
}
}
The conductor config is (template, gets generated by a makefile, see below):
bridges = []
persistence_dir = ''
ui_bundles = []
ui_interfaces = []
[[agents]]
id = 'hc-run-agent'
keystore_file = 'testAgent'
name = 'testAgent'
public_address = 'HcScjN8wBwrn3tuyg89aab3a69xsIgdzmX5P9537BqQZ5A7TEZu7qCY4Xzzjhma'
test_agent = true
[[dnas]]
file = "{{ c.DNA_FILE_PATH }}"
hash = "{{ c.DNA_HASH }}"
id = 'hc-run-dna'
[[instances]]
agent = 'hc-run-agent'
dna = 'hc-run-dna'
id = 'test-instance'
[instances.storage]
type = 'memory'
[[interfaces]]
admin = true
id = 'websocket-interface'
[interfaces.driver]
port = 8888
type = 'websocket'
[[interfaces.instances]]
id = 'test-instance'
[[interfaces]]
admin = true
id = 'http-interface'
[interfaces.driver]
port = 4000
type = 'http'
[[interfaces.instances]]
id = 'test-instance'
# --------- Network ----------
[network]
bootstrap_nodes = [
"wss://172.31.1.100:35268/?a=HcSCi6pCTkizyxh3u3yUzRaksU67abdfa7Cmjc83szhf89th7d69fNwvRS5t6ui"
]
n3h_log_level = 'i'
n3h_mode = 'REAL'
n3h_persistence_path = '{{ c.NH3_FOLDER }}'
type = 'n3h'
# ---------- Other -----------
[passphrase_service]
type = 'cmd'
[signals]
consistency = false
trace = false
# ---------- Logs -----------
[logger]
state_dump = true
type = 'debug'
[[logger.rules.rules]]
exclude = true
pattern = '.*'
[[logger.rules.rules]]
exclude = false
pattern = '^holochain'
[[logger.rules.rules]]
exclude = false
pattern = '^lib3h'
And I launch the whole thing with a makefile (I’ll including only the key lines here)
.DEFAULT_GOAL := hcconf
hcconf: deps gen-keys build
@tera -f hcconf_tpl.toml --env > .cache/hcconf.gen.toml
holochain -c .cache/hcconf.gen.toml
build:
hc package -o ${DNA_FILE_PATH}
# deps sets holochain and hc to 0.0.29, and rust to 1.38-nightly
# tera is what renders the holochain_config template
Thanks in advance