Created
December 5, 2019 06:13
-
-
Save freesig/1a2604d4c4ee7cdb2962ae582d580a43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(proc_macro_hygiene)] | |
#[macro_use] | |
extern crate hdk; | |
extern crate hdk_proc_macros; | |
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, | |
}; | |
use hdk::holochain_core_types::{ | |
dna::entry_types::Sharing, | |
}; | |
use hdk::holochain_json_api::{ | |
json::JsonString, | |
error::JsonError, | |
}; | |
use hdk_proc_macros::zome; | |
// this is a struct for the signal String. | |
#[derive(Serialize, Deserialize, Debug, DefaultJson,Clone)] | |
pub struct Signal { | |
signal: String | |
} | |
#[zome] | |
mod signal_zome { | |
#[init] | |
fn init() { | |
Ok(()) | |
} | |
#[validate_agent] | |
pub fn validate_agent(validation_data: EntryValidationData<AgentId>) { | |
Ok(()) | |
} | |
#[receive] | |
pub fn receive(_address: Address, _message: JsonString) -> String { | |
hdk::debug(format!("New message from: {:?}", _address)).ok(); | |
let success: Result<Signal, _> = JsonString::from_json(&_message).try_into(); | |
match success { | |
Err(err) => format!("error: {}", err), | |
Ok(message) => { | |
let _ = hdk::emit_signal(message.signal.as_str(), JsonString::from_json(&format!( | |
"{{message: {}}}", message | |
))) | |
.to_string(); | |
} | |
} | |
#[entry_def] | |
fn signal_entry_def() -> ValidatingEntryType { | |
entry!( | |
name: "signal", | |
description: "this is the current price enum as a string", | |
sharing: Sharing::Public, | |
validation_package: || { | |
hdk::ValidationPackageDefinition::Entry | |
}, | |
validation: | _validation_data: hdk::EntryValidationData<Signal>| { | |
Ok(()) | |
} | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Whoops I uploaded the wrong one.