Skip to content

Commit

Permalink
Merge pull request #35 from holonauts/feat/my-assigned-evaluations
Browse files Browse the repository at this point in the history
Feat/my assigned evaluations
  • Loading branch information
mattyg authored Feb 29, 2024
2 parents 8967ea6 + 56770d3 commit b7b757f
Show file tree
Hide file tree
Showing 57 changed files with 1,732 additions and 2,669 deletions.
93 changes: 86 additions & 7 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ serde_json = "1"
alloy-primitives = { version = "0.6.3", features = ["serde"] }
hc_zome_profiles_coordinator = { git = "https://github.com/holochain-open-dev/profiles.git", rev = "a1a487c8d6a8fd9910ba9b3f26e47df0bf0d09ae" }
hc_zome_profiles_integrity = { git = "https://github.com/holochain-open-dev/profiles.git", rev = "a1a487c8d6a8fd9910ba9b3f26e47df0bf0d09ae" }
rust_decimal = "1.34.3"

[workspace.dependencies.grants]
path = "dnas/grant_pools/zomes/coordinator/grants"
Expand Down
8 changes: 3 additions & 5 deletions dnas/grant_pools/zomes/coordinator/grants/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ name = "grants"

[dependencies]
hdk = { workspace = true }

serde = { workspace = true }

grants_integrity = { workspace = true }

alloy-primitives = { workspace = true }
grants_integrity = { workspace = true }
alloy-primitives = { workspace = true }
rust_decimal = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use alloy_primitives::Address;
use grants_integrity::*;
use hdk::prelude::*;

#[derive(Serialize, Deserialize, Debug)]
pub struct AddEvmWalletForAgentInput {
pub agent: AgentPubKey,
Expand All @@ -15,14 +14,11 @@ pub fn add_agent_to_evm_wallet_for_agent(input: AddEvmWalletForAgentInput) -> Ex
LinkTypes::AgentToEvmWallet,
input.evm_wallet.to_vec(),
)?;

Ok(())
}

#[hdk_extern]
pub fn get_agent_to_evm_wallets_for_agent(agent: AgentPubKey) -> ExternResult<Vec<String>> {
let links = get_links(agent, LinkTypes::AgentToEvmWallet, None)?;

let agent_to_evm_wallet: Vec<String> = links
.into_iter()
.map(|link| {
Expand All @@ -34,6 +30,5 @@ pub fn get_agent_to_evm_wallets_for_agent(agent: AgentPubKey) -> ExternResult<Ve
})
})
.collect::<ExternResult<Vec<String>>>()?;

Ok(agent_to_evm_wallet)
}
25 changes: 21 additions & 4 deletions dnas/grant_pools/zomes/coordinator/grants/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::grant_pool_to_applications::{
add_application_for_grant_pool, AddApplicationForGrantPoolInput,
use crate::{
evaluator_to_applications::{add_application_for_evaluator, AddApplicationForEvaluatorInput},
grant_pool_to_applications::{add_application_for_grant_pool, AddApplicationForGrantPoolInput},
};
use grants_integrity::*;
use hdk::prelude::*;

#[hdk_extern]
pub fn create_application(application: Application) -> ExternResult<Record> {
let application_hash = create_entry(&EntryTypes::Application(application.clone()))?;
Expand All @@ -25,9 +25,26 @@ pub fn create_application(application: Application) -> ExternResult<Record> {
(),
)?;
add_application_for_grant_pool(AddApplicationForGrantPoolInput {
base_grant_pool_hash: application.grant_pool,
base_grant_pool_hash: application.grant_pool.clone(),
target_application_hash: record.action_address().clone(),
})?;
let grant_pool_record = get(application.grant_pool, GetOptions::default())?.ok_or(
wasm_error!(WasmErrorInner::Guest("No grant pool found".into())),
)?;
let grant_pool: GrantPool = grant_pool_record
.entry()
.to_app_option()
.map_err(|e| wasm_error!(e))?
.ok_or(wasm_error!(WasmErrorInner::Guest(String::from(
"Record must contain an entry"
))))?;
for evaluator in grant_pool.evaluators {
add_application_for_evaluator(AddApplicationForEvaluatorInput {
base_evaluator: evaluator,
target_application_hash: application_hash.clone(),
})?;
}

Ok(record)
}
#[hdk_extern]
Expand Down
19 changes: 18 additions & 1 deletion dnas/grant_pools/zomes/coordinator/grants/src/evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,24 @@ pub fn get_evaluation(evaluation_hash: ActionHash) -> ExternResult<Option<Record
pub fn get_evaluations_for_application(application_hash: ActionHash) -> ExternResult<Vec<Link>> {
get_links(application_hash, LinkTypes::ApplicationToEvaluation, None)
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct GetEvaluationsForApplicationByAgent {
application_hash: ActionHash,
agent: AgentPubKey,
}
#[hdk_extern]
pub fn get_evaluations_for_application_by_agent(
input: GetEvaluationsForApplicationByAgent,
) -> ExternResult<Vec<Link>> {
Ok(get_links(
input.application_hash,
LinkTypes::ApplicationToEvaluation,
None,
)?
.into_iter()
.filter(|l| l.author == input.agent)
.collect())
}
pub fn get_score_for_evaluation(evaluation: Evaluation) -> u64 {
match evaluation.score {
Score::Single(score) => score,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use grants_integrity::*;
use hdk::prelude::*;

#[derive(Serialize, Deserialize, Debug)]
pub struct AddApplicationForEvaluatorInput {
pub base_evaluator: AgentPubKey,
pub target_application_hash: ActionHash,
}
#[hdk_extern]
pub fn add_application_for_evaluator(input: AddApplicationForEvaluatorInput) -> ExternResult<()> {
create_link(
input.base_evaluator.clone(),
input.target_application_hash.clone(),
LinkTypes::EvaluatorToApplications,
(),
)?;
create_link(
input.target_application_hash,
input.base_evaluator,
LinkTypes::ApplicationToEvaluators,
(),
)?;

Ok(())
}

#[hdk_extern]
pub fn get_applications_for_evaluator(evaluator: AgentPubKey) -> ExternResult<Vec<Link>> {
get_links(evaluator, LinkTypes::EvaluatorToApplications, None)
}

#[hdk_extern]
pub fn get_evaluators_for_application(application_hash: ActionHash) -> ExternResult<Vec<Link>> {
get_links(application_hash, LinkTypes::ApplicationToEvaluators, None)
}
29 changes: 12 additions & 17 deletions dnas/grant_pools/zomes/coordinator/grants/src/grant_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ pub fn create_grant_pool(grant_pool: GrantPool) -> ExternResult<Record> {
LinkTypes::EvaluationTemplateToGrantPools,
(),
)?;
let record = get(grant_pool_hash.clone(), GetOptions::default())?
.ok_or(
wasm_error!(
WasmErrorInner::Guest(String::from("Could not find the newly created GrantPool"))
),
)?;
let record = get(grant_pool_hash.clone(), GetOptions::default())?.ok_or(wasm_error!(
WasmErrorInner::Guest(String::from("Could not find the newly created GrantPool"))
))?;
let path = Path::from("all_grant_pools");
create_link(
path.path_entry_hash()?,
Expand All @@ -43,19 +40,13 @@ pub fn get_grant_pool(grant_pool_hash: ActionHash) -> ExternResult<Option<Record
};
match details {
Details::Record(details) => Ok(Some(details.record)),
_ => {
Err(
wasm_error!(
WasmErrorInner::Guest(String::from("Malformed get details response"))
),
)
}
_ => Err(wasm_error!(WasmErrorInner::Guest(String::from(
"Malformed get details response"
)))),
}
}
#[hdk_extern]
pub fn get_grant_pools_for_time_period(
time_period_hash: ActionHash,
) -> ExternResult<Vec<Link>> {
pub fn get_grant_pools_for_time_period(time_period_hash: ActionHash) -> ExternResult<Vec<Link>> {
get_links(time_period_hash, LinkTypes::TimePeriodToGrantPools, None)
}
#[hdk_extern]
Expand All @@ -72,5 +63,9 @@ pub fn get_grant_pools_for_application_template(
pub fn get_grant_pools_for_evaluation_template(
evaluation_template_hash: ActionHash,
) -> ExternResult<Vec<Link>> {
get_links(evaluation_template_hash, LinkTypes::EvaluationTemplateToGrantPools, None)
get_links(
evaluation_template_hash,
LinkTypes::EvaluationTemplateToGrantPools,
None,
)
}
Loading

0 comments on commit b7b757f

Please sign in to comment.