Make public is_passing and ReferendumStatus (#12667)

* init

* clean

* remove manual getter for ReferendumStatus in favor of changing pub crate to pub for ReferendumStatus DecidingStatus Deposit types

* rm status getters because fields are pub now
This commit is contained in:
Amar Singh
2022-11-15 04:37:12 -05:00
committed by GitHub
parent a9e85ecdfb
commit 8fef631a95
2 changed files with 40 additions and 15 deletions
+25
View File
@@ -701,6 +701,31 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}
}
/// Returns whether the referendum is passing.
/// Referendum must be ongoing and its track must exist.
pub fn is_referendum_passing(ref_index: ReferendumIndex) -> Result<bool, DispatchError> {
let info = ReferendumInfoFor::<T, I>::get(ref_index).ok_or(Error::<T, I>::BadReferendum)?;
match info {
ReferendumInfo::Ongoing(status) => {
let track = Self::track(status.track).ok_or(Error::<T, I>::NoTrack)?;
let elapsed = if let Some(deciding) = status.deciding {
frame_system::Pallet::<T>::block_number().saturating_sub(deciding.since)
} else {
Zero::zero()
};
Ok(Self::is_passing(
&status.tally,
elapsed,
track.decision_period,
&track.min_support,
&track.min_approval,
status.track,
))
},
_ => Err(Error::<T, I>::NotOngoing.into()),
}
}
// Enqueue a proposal from a referendum which has presumably passed.
fn schedule_enactment(
index: ReferendumIndex,