Skip to content

Commit

Permalink
Merge pull request #32 from holo-rea/feature/#19-basic-intent-api
Browse files Browse the repository at this point in the history
Looks good
  • Loading branch information
sqykly committed Jul 8, 2019
2 parents 29135de + f7242d2 commit 2976af6
Show file tree
Hide file tree
Showing 44 changed files with 1,571 additions and 545 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Expand Up @@ -6,6 +6,7 @@ members= [
"lib/vf_observation",
"lib/vf_planning",
"lib/vf_knowledge",
"happs/observation/zomes/main/code",
"happs/planning/zomes/main/code",
"happs/observation/zomes/economic_event/code",
"happs/planning/zomes/commitment/code",
"happs/planning/zomes/intent/code",
]
Expand Up @@ -7,5 +7,5 @@
"--target-dir=target"
]
},
"artifact": "target/wasm32-unknown-unknown/release/rea_observation_main.wasm"
"artifact": "target/wasm32-unknown-unknown/release/rea_observation_events.wasm"
}
@@ -1,5 +1,5 @@
[package]
name = "rea_observation_main"
name = "rea_observation_events"
version = "0.1.0"
authors = ["pospi <pospi@spadgos.com>"]
edition = "2018"
Expand Down
@@ -0,0 +1,80 @@
/**
* Handling for external request structure for economic event records
*/

use hdk::{
get_links,
holochain_core_types::{
cas::content::Address,
},
error::ZomeApiResult,
};

use hdk_graph_helpers::{
records::{
create_record,
read_record_entry,
update_record,
delete_record,
},
};
use vf_observation::economic_event::{
Entry as EconomicEventEntry,
CreateRequest as EconomicEventCreateRequest,
UpdateRequest as EconomicEventUpdateRequest,
ResponseData as EconomicEventResponse,
construct_response,
};
use super::fulfillment_requests::{
link_fulfillments,
get_fulfillments,
};

// Entry types

pub const EVENT_BASE_ENTRY_TYPE: &str = "vf_economic_event_base";
pub const EVENT_ENTRY_TYPE: &str = "vf_economic_event";

// :TODO: pull

pub fn handle_get_economic_event(address: Address) -> ZomeApiResult<EconomicEventResponse> {
let entry = read_record_entry(&address)?;

// It is important to note that there is no need to traverse the graph in any zome API read callbacks.
// When querying links, we only need to read the target addresses from the links EAV in our DHT.
// We leave it to the client GraphQL layer to handle fetching the details of associated fulfillments,
// which would be performed externally as a call to the associated `planning` DHT for "get_fulfillments".
let fulfillment_links = get_fulfillments(&address)?;

Ok(construct_response(&address, entry, Some(fulfillment_links)))
}

pub fn handle_create_economic_event(event: EconomicEventCreateRequest) -> ZomeApiResult<EconomicEventResponse> {
// copy necessary fields for link processing first, since `event.into()` will borrow the fields into the target Entry
let fulfills = event.get_fulfills();

let (base_address, entry_resp): (Address, EconomicEventEntry) = create_record(EVENT_BASE_ENTRY_TYPE, EVENT_ENTRY_TYPE, event)?;

// handle cross-DHT link fields
match fulfills.clone() {
Some(f) => { link_fulfillments(&base_address, &f)?; },
None => ()
};

// return entire record structure
Ok(construct_response(&base_address, entry_resp, fulfills))
}

pub fn handle_update_economic_event(event: EconomicEventUpdateRequest) -> ZomeApiResult<EconomicEventResponse> {
let base_address = event.get_id();
let new_entry = update_record(EVENT_ENTRY_TYPE, &base_address, &event)?;

// :TODO: link field handling
let fulfills = get_fulfillments(&base_address)?;

Ok(construct_response(base_address, new_entry, Some(fulfills)))
}

pub fn handle_delete_economic_event(address: Address) -> ZomeApiResult<bool> {
delete_record::<EconomicEventEntry>(&address)
}
@@ -0,0 +1,56 @@

/**
* Handling for `Fulfillment` related behaviours as they relate to `EconomicEvent`s
*/

use hdk::{
PUBLIC_TOKEN,
holochain_core_types::{
cas::content::Address,
json::JsonString,
},
error::ZomeApiResult,
utils::get_links_and_load_type,
};
use hdk_graph_helpers::{
links::create_remote_index_pair,
};

use vf_observation::{
BRIDGED_PLANNING_DHT,
};

// Entry types

pub const COMMITMENT_BASE_ENTRY_TYPE: &str = "vf_commitment_baseurl";

// Link tags / link field names

pub const EVENT_FULFILLS_LINK_TYPE: &str = "vf_economic_event_fulfills";
pub const COMMITMENT_FULFILLEDBY_LINK_TYPE: &str = "vf_commitment_fulfilled_by";

pub const LINK_TAG_EVENT_FULFILLS: &str = "fulfills";
pub const LINK_TAG_COMMITMENT_FULFILLEDBY: &str = "fulfilled_by";

pub fn handle_link_fulfillments(economic_event: Address, commitments: Vec<Address>) -> ZomeApiResult<Vec<Address>> {
link_fulfillments(&economic_event, &commitments)
}

pub fn link_fulfillments(source_entry: &Address, targets: &Vec<Address>) -> ZomeApiResult<Vec<Address>> {
create_remote_index_pair(
BRIDGED_PLANNING_DHT,
"commitment",
"link_fulfillments",
// &PUBLIC_TOKEN,
Address::from(PUBLIC_TOKEN.to_string()),
COMMITMENT_BASE_ENTRY_TYPE,
EVENT_FULFILLS_LINK_TYPE, LINK_TAG_EVENT_FULFILLS,
COMMITMENT_FULFILLEDBY_LINK_TYPE, LINK_TAG_COMMITMENT_FULFILLEDBY,
source_entry,
targets,
)
}

pub fn get_fulfillments(address: &Address) -> ZomeApiResult<Vec<Address>> {
get_links_and_load_type(&address, Some(EVENT_FULFILLS_LINK_TYPE.to_string()), Some(LINK_TAG_EVENT_FULFILLS.to_string()))
}
Expand Up @@ -16,6 +16,7 @@ extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate hdk_graph_helpers;
extern crate vf_observation;
mod economic_event_requests;
mod fulfillment_requests;
Expand All @@ -31,23 +32,23 @@ use hdk::holochain_core_types::{
json::JsonString,
};

use hdk_graph_helpers::{
LINK_TYPE_INITIAL_ENTRY,
};
use vf_observation::economic_event::{
Entry as EconomicEventEntry,
CreateRequest as EconomicEventCreateRequest,
UpdateRequest as EconomicEventUpdateRequest,
ResponseData as EconomicEventResponse,
};

use economic_event_requests::{
EVENT_ENTRY_TYPE,
EVENT_BASE_ENTRY_TYPE,
LINK_TYPE_INITIAL_ENTRY,
handle_get_economic_event,
handle_create_economic_event,
handle_update_economic_event,
handle_delete_economic_event,
};
// handle_update_economic_event,
use fulfillment_requests::{
COMMITMENT_BASE_ENTRY_TYPE,
EVENT_FULFILLS_LINK_TYPE,
Expand Down
File renamed without changes.
132 changes: 0 additions & 132 deletions happs/observation/zomes/main/code/src/economic_event_requests.rs

This file was deleted.

0 comments on commit 2976af6

Please sign in to comment.