Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Looks good
- Loading branch information
Showing
44 changed files
with
1,571 additions
and
545 deletions.
There are no files selected for viewing
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
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
2 changes: 1 addition & 1 deletion
2
happs/observation/zomes/main/code/Cargo.toml → ...tion/zomes/economic_event/code/Cargo.toml
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
80 changes: 80 additions & 0 deletions
80
happs/observation/zomes/economic_event/code/src/economic_event_requests.rs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
56 changes: 56 additions & 0 deletions
56
happs/observation/zomes/economic_event/code/src/fulfillment_requests.rs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())) | ||
} |
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
File renamed without changes.
132 changes: 0 additions & 132 deletions
132
happs/observation/zomes/main/code/src/economic_event_requests.rs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.