8000 add edge randomizer field by Connoropolous · Pull Request #100 · h-be/acorn-hc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.

add edge randomizer field #100

Merged
merged 1 commit into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
6 changes: 3 additions & 3 deletions dnas/projects/zomes/acorn_projects/code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod project;

use project::{
ArchiveGoalResponse, Edge, EntryPoint, EntryPointResponse, GetHistoryResponse, GetResponse, Goal,
GoalComment, GoalMaybeWithEdge, GoalMember, GoalVote, Member, ProjectMeta,
GoalComment, GoalMaybeWithEdge, GoalMember, GoalVote, Member, ProjectMeta, GoalEdgeInput,
};
//The GetResponse struct allows our zome functions to return an entry along with its
//address so that Redux can know the address of goals and edges
Expand Down Expand Up @@ -293,9 +293,9 @@ mod holo_acorn {
#[zome_fn("hc_public")]
fn create_goal(
goal: Goal,
maybe_parent_address: Option<Address>,
maybe_goal_edge_input: Option<GoalEdgeInput>,
) -> ZomeApiResult<GoalMaybeWithEdge> {
project::create_goal(goal, maybe_parent_address)
project::create_goal(goal, maybe_goal_edge_input)
}

#[zome_fn("hc_public")]
Expand Down
16 changes: 12 additions & 4 deletions dnas/projects/zomes/acorn_projects/code/src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ use crate::{
GoalMemberSignalPayload, GoalVoteSignalPayload, NewMemberSignalPayload,
};

#[derive(Serialize, Deserialize, Debug, DefaultJson, Clone, PartialEq)]
pub struct GoalEdgeInput {
parent_address: Address,
randomizer: u128,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct GetResponse<T> {
pub entry: T,
Expand Down Expand Up @@ -111,6 +117,7 @@ pub struct GoalComment {
pub struct Edge {
parent_address: Address,
child_address: Address,
randomizer: u128,
}

#[derive(Serialize, Deserialize, Debug, DefaultJson, Clone, PartialEq)]
Expand Down Expand Up @@ -612,7 +619,7 @@ pub fn history_of_goal(address: Address) -> ZomeApiResult<GetHistoryResponse> {

pub fn create_goal(
goal: Goal,
maybe_parent_address: Option<Address>,
maybe_goal_edge_input: Option<GoalEdgeInput>,
) -> ZomeApiResult<GoalMaybeWithEdge> {
let app_entry = Entry::App("goal".into(), goal.clone().into());
let entry_address = hdk::commit_entry(&app_entry)?;
Expand All @@ -627,11 +634,12 @@ pub fn create_goal(
hdk::link_entries(&anchor_address, &app_entry.address(), "anchor->goal", "")?;

// if a parent address was provided, link the goal with its parent
let maybe_edge = match maybe_parent_address {
Some(parent_address) => {
let maybe_edge = match maybe_goal_edge_input {
Some(goal_edge_input) => {
let edge: Edge = Edge {
parent_address: parent_address,
parent_address: goal_edge_input.parent_address,
child_address: entry_address.clone(),
randomizer: goal_edge_input.randomizer,
};
let edge_address = inner_create_edge(&edge)?;
Some(GetResponse {
Expand Down
19 changes: 11 additions & 8 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ orchestrator.registerScenario('create goal test', async (s, t) => {
status: 'Uncertain',
description: ''
},
maybe_parent_address: null
maybe_goal_edge_input: null
})

// Wait for all network activity to
Expand Down Expand Up @@ -185,7 +185,7 @@ orchestrator.registerScenario(
status: 'Uncertain',
description: ''
},
maybe_parent_address: null
maybe_goal_edge_input: null
})
await s.consistency()
const addr2 = await alice.call(
Expand All @@ -201,7 +201,7 @@ orchestrator.registerScenario(
status: 'Uncertain',
description: ''
},
maybe_parent_address: null
maybe_goal_edge_input: null
}
)
await s.consistency()
Expand Down Expand Up @@ -297,7 +297,7 @@ orchestrator.registerScenario('create goal test', async (s, t) => {
status: 'Uncertain',
description: ''
},
maybe_parent_address: null
maybe_goal_edge_input: null
})

// Wait for all network activity to
Expand Down Expand Up @@ -413,7 +413,7 @@ orchestrator.registerScenario(
status: 'Uncertain',
description: ''
},
maybe_parent_address: null
maybe_goal_edge_input: null
})

const goal2 = await bob.call('projects', 'acorn_projects', 'create_goal', {
Expand All @@ -429,7 +429,10 @@ orchestrator.registerScenario(
to_date: Date.parse('Aug 9, 2020')
}
},
maybe_parent_address: goal.Ok.goal.address
maybe_goal_edge_input: {
parent_address: goal.Ok.goal.address,
randomizer: Date.now()
}
})

// Wait for all network activity to
Expand Down Expand Up @@ -604,7 +607,7 @@ orchestrator.registerScenario(
status: 'Uncertain',
description: ''
},
maybe_parent_address: null
maybe_goal_edge_input: null
}
)
await s.consistency()
Expand Down Expand Up @@ -663,7 +666,7 @@ orchestrator.registerScenario('alex and alice are commenting', async (s, t) => {
status: 'Uncertain',
description: ''
},
maybe_parent_address: null
maybe_goal_edge_input: null
})
const comment1 = await alice.call(
'projects',
Expand Down
0