Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TrustGraph Refactor #43

Closed
wants to merge 13 commits into from
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,24 @@ We encode TrustAtoms as links, with the following components:

```
Ŧ→[0x00]prefix[0x00]sushi[0x00]0.999999999[0x00]892412523[0x00]uhCEk…UFnFF
<<<<<<< HEAD
Ŧ↩[0x00]prefix[0x00]sushi[0x00]0.999999999[0x00]892412523[0x00]uhCEk…UFnFF

Ŧ→[0x00]rollup[0x00]content[0x00]0.800000000[0x00]087423432[0x00]uhCEk…qS5wc
Ŧ↩[0x00]rollup[0x00]content[0x00]0.800000000[0x00]087423432[0x00]uhCEk…qS5wc

Ŧ→[0x00]entry[0x00]spam[0x00]-0.999999999[0x00]328425615[0x00]uhCEk…VaaDd
Ŧ→[0x00]agent[0x00]block[0x00]-0.999999999[0x00]837592944[0x00]uhCEk…VaaDd
=======
Ŧ→[0x00]sushi[0x00]0.999999999[0x00]892412523[0x00]uhCEk…UFnFF
Ŧ↩[0x00]sushi[0x00]0.999999999[0x00]892412523[0x00]uhCEk…UFnFF

Ŧ→[0x00]sushi[0x00]0.800000000[0x00]087423432[0x00]uhCEk…qS5wc
Ŧ↩[0x00]sushi[0x00]0.800000000[0x00]087423432[0x00]uhCEk…qS5wc

Ŧ→[0x00]spam[0x00]-0.999999999[0x00]328425615[0x00]uhCEk…VaaDd
Ŧ→agent[0x00]block[0x00]-0.999999999[0x00]837592944[0x00]uhCEk…VaaDd
>>>>>>> 5376c48 (add label (type) to TA)
```

## Roadmap
Expand Down
66 changes: 55 additions & 11 deletions zomes/hc_zome_trust_atom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@
// #![warn(clippy::cargo)]

use hdk::prelude::*;

use std::collections::BTreeMap;

// public for sweettest; TODO can we fix this:
pub mod trust_atom;
pub use crate::trust_atom::*;
pub use trust_atom::*;
pub mod trust_graph;
pub use trust_graph::*;
pub mod test_helpers;
pub use test_helpers::Test;
pub mod utils;
pub use utils::*;

entry_defs![
test_helpers::StringTarget::entry_def(),
Expand All @@ -29,6 +34,19 @@ entry_defs![

#[derive(Serialize, Deserialize, SerializedBytes, Debug, Clone)]
pub struct TrustAtomInput {
pub prefix: Option<String>,
pub target: AnyLinkableHash,
pub content: Option<String>,
pub value: Option<String>,
pub extra: Option<BTreeMap<String, String>>,
// for rollups key is "rolled_up_trust_atoms"
// value is json: '["header hash of atom 1","header hash of atom 2"...]'
}

#[derive(Serialize, Deserialize, SerializedBytes, Debug, Clone)]
pub struct TestHelperTrustAtomInput {
pub source: AnyLinkableHash,
pub prefix: Option<String>,
pub target: AnyLinkableHash,
pub content: Option<String>,
pub value: Option<String>,
Expand All @@ -39,6 +57,7 @@ pub struct TrustAtomInput {
pub struct QueryInput {
pub source: Option<AnyLinkableHash>,
pub target: Option<AnyLinkableHash>,
pub prefix: Option<String>,
pub content_full: Option<String>,
pub content_starts_with: Option<String>,
pub value_starts_with: Option<String>,
Expand All @@ -47,37 +66,55 @@ pub struct QueryInput {
#[derive(Serialize, Deserialize, SerializedBytes, Debug, Clone)]
pub struct QueryMineInput {
pub target: Option<AnyLinkableHash>,
pub prefix: Option<String>,
pub content_full: Option<String>,
pub content_starts_with: Option<String>,
pub value_starts_with: Option<String>,
}

// ZOME API FUNCTIONS

#[hdk_extern]
pub fn create_rollup_atoms(_: ()) -> ExternResult<Vec<TrustAtom>> {
trust_graph::create_rollup_atoms()
}

#[hdk_extern]
pub fn create_trust_atom(input: TrustAtomInput) -> ExternResult<TrustAtom> {
let trust_atom = trust_atom::create(input.target, input.content, input.value, input.extra)?;
Ok(trust_atom)
trust_atom::create_mine_trust_atom(
input.target,
input.prefix,
input.content,
input.value,
input.extra,
)
}

#[hdk_extern]
#[allow(clippy::needless_pass_by_value)]
pub fn get_extra(entry_hash: EntryHash) -> ExternResult<Extra> {
let extra = trust_atom::get_extra(&entry_hash)?;
Ok(extra)
// TEST HELPER move me
pub fn test_helper_create_trust_atom(input: TestHelperTrustAtomInput) -> ExternResult<TrustAtom> {
trust_atom::create_trust_atom(
input.source,
input.target,
input.prefix,
input.content,
input.value,
input.extra,
)
}

#[hdk_extern]
pub fn calc_extra_hash(input: Extra) -> ExternResult<EntryHash> {
let hash = trust_atom::calc_extra_hash(input)?;
Ok(hash)
#[allow(clippy::needless_pass_by_value)]
pub fn get_extra(entry_hash: EntryHash) -> ExternResult<Extra> {
trust_atom::get_extra(&entry_hash)
}

#[hdk_extern]
pub fn query(input: QueryInput) -> ExternResult<Vec<TrustAtom>> {
trust_atom::query(
input.source,
input.target,
input.prefix,
input.content_full,
input.content_starts_with,
input.value_starts_with,
Expand All @@ -88,16 +125,18 @@ pub fn query(input: QueryInput) -> ExternResult<Vec<TrustAtom>> {
pub fn query_mine(input: QueryMineInput) -> ExternResult<Vec<TrustAtom>> {
trust_atom::query_mine(
input.target,
input.prefix,
input.content_full,
input.content_starts_with,
input.value_starts_with,
)
}

// TEST HELPERS

#[hdk_extern]
pub fn create_string_target(input: String) -> ExternResult<EntryHash> {
crate::test_helpers::create_string_target(input)
test_helpers::create_string_target(input)
}

#[hdk_extern]
Expand All @@ -121,3 +160,8 @@ pub fn test_helper_list_links(
pub fn test_helper_list_links_for_base(base: AnyLinkableHash) -> ExternResult<Vec<Link>> {
test_helpers::list_links_for_base(base)
}

#[hdk_extern]
pub fn test_helper_calc_extra_hash(input: Extra) -> ExternResult<EntryHash> {
test_helpers::calc_extra_hash(input)
}
5 changes: 5 additions & 0 deletions zomes/hc_zome_trust_atom/src/test_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(clippy::module_name_repetitions)]

use crate::trust_atom::Extra;
use hdk::prelude::*;

#[derive(Serialize, Deserialize, Debug, SerializedBytes)]
Expand Down Expand Up @@ -80,3 +81,7 @@ fn get_element_by_header(
))),
}
}

pub fn calc_extra_hash(input: Extra) -> ExternResult<EntryHash> {
hash_entry(input)
}
Loading