Skip to content

Commit

Permalink
Merge pull request #131 from lightningrodlabs/feature/signals-und-yati
Browse files Browse the repository at this point in the history
Feature/signals und yati
  • Loading branch information
adaburrows authored Aug 24, 2022
2 parents 64afd3b + ea2fc39 commit e5cd297
Show file tree
Hide file tree
Showing 41 changed files with 2,192 additions and 672 deletions.
124 changes: 108 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions environments/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
REA_PLAYSPACE_APP_ID='rea-playspace'
REA_PLAYSPACE_ADMIN_WS_PORT=1234
REA_PLAYSPACE_APP_WS_PORT=8888
REA_PLAYSPACE_DATASTORE_PATH='user-data/databases'
REA_PLAYSPACE_KEYSTORE_PATH='user-data/keystore'
REA_PLAYSPACE_ROOT='/tmp/hc/'
REA_PLAYSPACE_DIR='user-data'
4 changes: 2 additions & 2 deletions environments/.env.dev2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
REA_PLAYSPACE_APP_ID='rea-playspace'
REA_PLAYSPACE_ADMIN_WS_PORT=1236
REA_PLAYSPACE_APP_WS_PORT=8899
REA_PLAYSPACE_DATASTORE_PATH='user2-data/databases'
REA_PLAYSPACE_KEYSTORE_PATH='user2-data/keystore/'
REA_PLAYSPACE_ROOT='/tmp/hc/'
REA_PLAYSPACE_DIR='user2-data'
EH_TEST_USER_2=1
2 changes: 2 additions & 0 deletions happ/zomes/projects/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ derive_more = "0"
serde = "*"
paste = "*"
tracing = "0.1.26"
hc_zome_profiles_types = { git = "https://github.com/holochain-open-dev/profiles", rev = "for-hdk-v0.0.142", package = "hc_zome_profiles_types" }

8 changes: 7 additions & 1 deletion happ/zomes/projects/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hdk::prelude::*;
use hdk::prelude::{*};
use holo_hash::{ActionHashB64, EntryHashB64};

// returned after successful write to DHT
Expand All @@ -22,6 +22,12 @@ pub struct Content {
pub data: String,
}

// Remote call input
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SignalPayload {
pub message: String
}

#[derive(Clone, Serialize, Deserialize, Debug, Default)]
pub struct Tree<T>
where
Expand Down
70 changes: 70 additions & 0 deletions happ/zomes/projects/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,83 @@ mod test;
mod data;
mod tree_clean;

//use hc_zome_profiles_types::Profile;
use hdk::{prelude::*, hash_path::path::Component};
use holo_hash::{EntryHashB64, ActionHashB64};
use tracing::{info};
use data::*;
use tree_clean::{mark_tree, reindex_tree, prune_tree};
use projects_core::{EntryTypes, LinkTypes, Thing};

#[hdk_extern]
pub fn init(_: ()) -> ExternResult<InitCallbackResult> {
let mut functions = GrantedFunctions::new();
functions.insert((ZomeName::new("projects"), FunctionName::new("remote_update_for_ui")));
let grant = ZomeCallCapGrant {
access: CapAccess::Unrestricted,
functions,
tag: "".into(),
};
create_cap_grant(grant.into())?;
debug!("Init success");
Ok(InitCallbackResult::Pass)
}

// /**
// * The UI will call this function when a change has been made when a CRUD operation has occured resulting to a change in UI state
// */
#[hdk_extern]
pub fn ui_updated(message: String) -> ExternResult<()> {
// get vec of all profiles
let response: ZomeCallResponse = call(
CallTargetCell::Local,
ZomeName::new("profiles"),
FunctionName::new("get_all_profiles"),
None,
()
)?;

let records: Vec<Record> = match response {
ZomeCallResponse::Ok(content)=> Ok(content),
_ => Err(wasm_error!(WasmErrorInner::Guest("Network, Unauthorized, or Countersigning error".into())))
}?.decode::<Vec<Record>>().unwrap();

let mut all_agent_pub_keys: Vec<AgentPubKey> = Vec::new();
for record in records {
all_agent_pub_keys.push(record.signed_action.action().author().to_owned());
}

// Send a signal to all other agents
let this_agent_pub_key: AgentPubKey = agent_info()?.agent_initial_pubkey;
let other_agent_pub_keys: Vec<AgentPubKey> = all_agent_pub_keys.into_iter().filter(|x| *x != this_agent_pub_key).collect();

for other in other_agent_pub_keys {
let payload = SignalPayload {
message: message.clone()
};
debug!("Called agent {:?}", other.clone());

call_remote(
other,
ZomeName::new("projects"),
FunctionName::new("remote_update_for_ui"),
None,
payload.clone()
)?;
debug!("Called remote_update_for_ui with payload {:?}", payload);
}

Ok(())
}

// // agents call this function in other cells. emit_signal will be handled by a signalCallback in frontend
#[hdk_extern]
pub fn remote_update_for_ui(payload: SignalPayload) -> ExternResult<()> {
emit_signal(payload.clone())?;
debug!("External Call Recieved: update_for_ui with payload: {:?}", payload);
Ok(())
}

#[hdk_extern]
pub fn put_thing(input: ThingInput) -> ExternResult<AddOutput> {
info!("putting thing with path {}", input.path.clone());
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"web-install": "cd ui && pnpm install",

"// ## HOLOCHAIN ##": "",
"hc:redo": "pnpm run hc:reset && pnpm run hc:run",
"hc:redo": "pnpm run hc:happ-pack && pnpm run hc:run",
"hc:happ-pack": "bash scripts/happ-pack.sh",
"hc:reset": "pnpm run hc:happ-pack && rm -rf .hc*",
"hc:run": "sh -c 'set -o allexport; . environments/.env; set +o allexport; . scripts/happ-run.sh'",
"hc:run2": "sh -c 'set -o allexport; . environments/.env.dev2; set +o allexport; . scripts/happ-run.sh'",
"hc:run": "sh -c 'set -o allexport; . environments/.env; set +o allexport; rm -rf $REA_PLAYSPACE_ROOT$REA_PLAYSPACE_DIR; . scripts/happ-run.sh'",
"hc:run2": "sh -c 'set -o allexport; . environments/.env.dev2; set +o allexport; rm -rf $REA_PLAYSPACE_ROOT$REA_PLAYSPACE_DIR; . scripts/happ-run.sh'",
"playground": "sh -c 'set -o allexport; . environments/.env; set +o allexport; npx @holochain-playground/cli ws://localhost:$REA_PLAYSPACE_ADMIN_WS_PORT'",
"playground2": "sh -c 'set -o allexport; . environments/.env.dev2; set +o allexport; npx @holochain-playground/cli ws://localhost:$REA_PLAYSPACE_ADMIN_WS_PORT'",
"webhapp-pack": "pnpm run web-zip && hc web-app pack workdir/",

"// ## UI ##": "",
Expand Down
6 changes: 2 additions & 4 deletions scripts/happ-run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# This file needs an environment sourced before it will run
#!/bin/bash
RUST_LOG=warn WASM_LOG=debug hc s -f=$REA_PLAYSPACE_ADMIN_WS_PORT generate ./happ/workdir/application.happ --run=$REA_PLAYSPACE_APP_WS_PORT -a $REA_PLAYSPACE_APP_ID network mdns



RUST_LOG=warn WASM_LOG=debug hc sandbox -f=$REA_PLAYSPACE_ADMIN_WS_PORT generate --root=$REA_PLAYSPACE_ROOT -d=$REA_PLAYSPACE_DIR ./happ/workdir/application.happ --run=$REA_PLAYSPACE_APP_WS_PORT -a $REA_PLAYSPACE_APP_ID network mdns
#RUST_LOG=warn WASM_LOG=debug hc sandbox -f=$REA_PLAYSPACE_ADMIN_WS_PORT run -e=$REA_PLAYSPACE_ROOT$REA_PLAYSPACE_DIR -p $REA_PLAYSPACE_APP_WS_PORT --all
Loading

0 comments on commit e5cd297

Please sign in to comment.