Browse Source

referendum - current cycle id counter removal II

ondratra 4 years ago
parent
commit
5636e6e9b9
2 changed files with 7 additions and 15 deletions
  1. 6 10
      runtime-modules/council/src/lib.rs
  2. 1 5
      runtime-modules/council/src/mock.rs

+ 6 - 10
runtime-modules/council/src/lib.rs

@@ -249,10 +249,7 @@ pub trait ReferendumConnection<T: Trait> {
     fn recieve_referendum_results(winners: &[OptionResult<VotePowerOf<T>>]);
 
     /// Process referendum results. This function MUST be called in runtime's implementation of referendum's `can_release_voting_stake()`.
-    fn can_unlock_vote_stake(
-        vote: &CastVoteOf<T>,
-        current_voting_cycle_id: &u64,
-    ) -> Result<(), Error<T>>;
+    fn can_unlock_vote_stake(vote: &CastVoteOf<T>) -> Result<(), Error<T>>;
 
     /// Checks that user is indeed candidating. This function MUST be called in runtime's implementation of referendum's `is_valid_option_id()`.
     fn is_valid_candidate_id(membership_id: &T::MembershipId) -> bool;
@@ -756,12 +753,11 @@ impl<T: Trait> ReferendumConnection<T> for Module<T> {
     }
 
     /// Check that it is a proper time to release stake.
-    fn can_unlock_vote_stake(
-        vote: &CastVoteOf<T>,
-        current_voting_cycle_id: &u64,
-    ) -> Result<(), Error<T>> {
+    fn can_unlock_vote_stake(vote: &CastVoteOf<T>) -> Result<(), Error<T>> {
+        let current_voting_cycle_id = AnnouncementPeriodNr::get();
+
         // allow release for very old votes
-        if *current_voting_cycle_id > vote.cycle_id + 1 {
+        if current_voting_cycle_id > vote.cycle_id + 1 {
             return Ok(());
         }
 
@@ -771,7 +767,7 @@ impl<T: Trait> ReferendumConnection<T> for Module<T> {
             .any(|membership_id| vote.vote_for == Some(membership_id.into()));
 
         // allow release for vote from previous elections only when not voted for winner
-        if *current_voting_cycle_id == vote.cycle_id + 1 {
+        if current_voting_cycle_id == vote.cycle_id + 1 {
             // ensure vote was not cast for the one of winning candidates / council members
             if voting_for_winner {
                 return Err(Error::CantReleaseStakeNow);

+ 1 - 5
runtime-modules/council/src/mock.rs

@@ -221,11 +221,7 @@ impl referendum::Trait<ReferendumInstance> for RuntimeReferendum {
             return false;
         }
 
-        <Module<Runtime> as ReferendumConnection<Runtime>>::can_unlock_vote_stake(
-            vote,
-            &AnnouncementPeriodNr::get(),
-        )
-        .is_ok()
+        <Module<Runtime> as ReferendumConnection<Runtime>>::can_unlock_vote_stake(vote).is_ok()
     }
 
     fn process_results(winners: &[OptionResult<Self::VotePower>]) {