From 33cd2cc1a695908a0134d497ade747e2ab4fcec4 Mon Sep 17 00:00:00 2001 From: Franco Testagrossa Date: Fri, 3 May 2024 22:55:05 +0200 Subject: [PATCH] Add pr nbr as part of accept --- bounty/bounty.did | 4 ++-- bounty/src/api/accept.rs | 16 ++++++++++------ bounty/src/api/init.rs | 4 +++- bounty/src/api/state.rs | 9 +++++++-- bounty/src/lib.rs | 4 ++-- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/bounty/bounty.did b/bounty/bounty.did index b67ce12..1735173 100644 --- a/bounty/bounty.did +++ b/bounty/bounty.did @@ -12,9 +12,9 @@ type DepositErr = variant { TransferFailure : record { reason : text }; }; -service : (principal, int32) -> { +service : (authority: principal, github_issue_id: int32) -> { "healthcheck": () -> (text); - "accept": (Contributor) -> (); + "accept": (Contributor, github_pr_id: int32) -> (); "deposit": () -> (DepositReceipt); } diff --git a/bounty/src/api/accept.rs b/bounty/src/api/accept.rs index 5ee4ced..f14610e 100644 --- a/bounty/src/api/accept.rs +++ b/bounty/src/api/accept.rs @@ -1,10 +1,10 @@ use super::state::{Contributor, BOUNTY_STATE}; -pub fn accept_impl(contributor: Contributor) -> () { +pub fn accept_impl(contributor: Contributor, github_pr_id: i32) -> () { BOUNTY_STATE.with(|state| { if let Some(ref mut bounty_canister) = *state.borrow_mut() { // Add the contributor to the interested contributors list - bounty_canister.interested_contributors.push(contributor); + bounty_canister.interested_contributors.insert(github_pr_id, contributor); } }); } @@ -32,10 +32,14 @@ mod test_accept { let contributor = Principal::from_text("t2y5w-qp34w-qixaj-s67wp-syrei-5yqse-xbed6-z5nsd-fszmf-izgt2-lqe") .unwrap(); - accept_impl(Contributor { - address: contributor, - crypto_address: "contributor_address".to_string(), - }); + let github_pr_id = 88; + accept_impl( + Contributor { + address: contributor, + crypto_address: "contributor_address".to_string(), + }, + github_pr_id, + ); BOUNTY_STATE.with(|state| { let bounty_canister = state.borrow(); if let Some(ref bounty_canister) = *bounty_canister { diff --git a/bounty/src/api/init.rs b/bounty/src/api/init.rs index 2bc87bf..15ecda8 100644 --- a/bounty/src/api/init.rs +++ b/bounty/src/api/init.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use super::state::{BountyState, BOUNTY_STATE}; use candid::Principal; @@ -6,7 +8,7 @@ pub fn init_impl(authority: Principal, github_issue_id: i32) -> () { *state.borrow_mut() = Some(BountyState { authority, github_issue_id, - interested_contributors: Vec::new(), + interested_contributors: HashMap::new(), claimed: false, }); }); diff --git a/bounty/src/api/state.rs b/bounty/src/api/state.rs index b95615b..f8c0c72 100644 --- a/bounty/src/api/state.rs +++ b/bounty/src/api/state.rs @@ -1,11 +1,16 @@ +use std::collections::HashMap; + use candid::{CandidType, Principal}; use serde::{Deserialize, Serialize}; +type IssueId = i32; +type PullRequestId = i32; + #[derive(Debug, Serialize, Deserialize, CandidType)] pub struct BountyState { pub authority: Principal, - pub github_issue_id: i32, - pub interested_contributors: Vec, + pub github_issue_id: IssueId, + pub interested_contributors: HashMap, pub claimed: bool, } diff --git a/bounty/src/lib.rs b/bounty/src/lib.rs index f128697..15e374c 100644 --- a/bounty/src/lib.rs +++ b/bounty/src/lib.rs @@ -19,8 +19,8 @@ fn init(authority: Principal, github_issue_id: i32) -> () { } #[ic_cdk::update] -fn accept(contributor: Contributor) -> () { - accept_impl(contributor); +fn accept(contributor: Contributor, github_pr_id: i32) -> () { + accept_impl(contributor, github_pr_id); } #[ic_cdk::update]