Skip to content

Commit

Permalink
wonlost
Browse files Browse the repository at this point in the history
  • Loading branch information
amiyatulu committed Jun 5, 2024
1 parent dd2b381 commit a574097
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 8 deletions.
28 changes: 21 additions & 7 deletions custom-pallets/project-tips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,16 +374,30 @@ use super::*;

#[pallet::call_index(8)]
#[pallet::weight(0)]
pub fn get_incentives(origin: OriginFor<T>, project_id: ProjectId) -> DispatchResult {
pub fn add_incentive_count(
origin: OriginFor<T>,
project_id: ProjectId

) -> DispatchResult {
let who = ensure_signed(origin)?;
let block_number = Self::get_block_number_of_schelling_game(project_id)?;
let key = SumTreeName::ProjectTips { project_id, block_number: block_number.clone() };

let phase_data = Self::get_phase_data();
T::SchellingGameSharedSource::get_incentives_two_choice_helper_link(
key, phase_data, who,
)?;
// let key = SumTreeName::ProjectTips { project_id, block_number: block_number.clone() };
Ok(())

}

// #[pallet::call_index(8)]
// #[pallet::weight(0)]
// pub fn get_incentives(origin: OriginFor<T>, project_id: ProjectId) -> DispatchResult {
// let who = ensure_signed(origin)?;
// let block_number = Self::get_block_number_of_schelling_game(project_id)?;
// let key = SumTreeName::ProjectTips { project_id, block_number: block_number.clone() };

// let phase_data = Self::get_phase_data();
// T::SchellingGameSharedSource::get_incentives_two_choice_helper_link(
// key, phase_data, who,
// )?;
// Ok(())
// }
}
}
55 changes: 55 additions & 0 deletions custom-pallets/schelling-game-shared/src/extras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,61 @@ impl<T: Config> Pallet<T> {
Ok(())
}


pub(super) fn get_result_of_juror(
key: SumTreeNameType<T>,
who: AccountIdOf<T>
) -> Result<WonLost, DispatchError> {
match <PeriodName<T>>::get(&key) {
Some(period) => {
ensure!(period == Period::Execution, Error::<T>::PeriodDontMatch);
},
None => Err(Error::<T>::PeriodDoesNotExists)?,
}

let drawn_juror = <DrawnJurors<T>>::get(&key);

let who_commit_vote = <VoteCommits<T>>::get(&key, &who);
match who_commit_vote {
Some(commit_struct) => {
let vote_option = commit_struct.revealed_vote;
match vote_option {
Some(vote) => {
let decision_count: (u64, u64) = <DecisionCount<T>>::get(&key);
let winning_decision = Self::get_winning_decision(decision_count);
if let Ok(_) = drawn_juror.binary_search_by(|(c, _)| c.cmp(&who.clone())) {
match winning_decision {
WinningDecision::WinnerYes => match vote {
RevealedVote::Yes => {
Ok(WonLost::Won)
},
RevealedVote::No => {
Ok(WonLost::Lost)
},
},
WinningDecision::WinnerNo => match vote {
RevealedVote::Yes => {
Ok(WonLost::Lost)
},
RevealedVote::No => {
Ok(WonLost::Won)
},
},
WinningDecision::Draw => {
Ok(WonLost::Lost)
},
}
} else {
Err(Error::<T>::StakeDoesNotExists)?
}
},
None => Err(Error::<T>::VoteNotRevealed)?,
}
},
None => Err(Error::<T>::CommitDoesNotExists)?,
}
}

pub(super) fn getting_incentives_draw(
key: SumTreeNameType<T>,
who: AccountIdOf<T>,
Expand Down
2 changes: 1 addition & 1 deletion custom-pallets/schelling-game-shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod types;

use crate::types::{
CommitVote, Period, PhaseData, RangePoint, RevealedVote, SchellingGameType, ScoreCommitVote,
VoteStatus, WinningDecision,
VoteStatus, WinningDecision, WonLost
};
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
Expand Down
12 changes: 12 additions & 0 deletions custom-pallets/schelling-game-shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ pub enum WinningDecision {
Draw,
}


#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum WonLost {
Won,
Lost,
Draw,
}




#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct ScoreCommitVote {
Expand Down

0 comments on commit a574097

Please sign in to comment.