Feedback from @XLC for Referenda Pallet (#10991)

* feedback from @xlc

* english

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
Shawn Tabrizi
2022-03-08 08:48:30 -04:00
committed by GitHub
parent c6d653ffc8
commit 64f6664691
6 changed files with 47 additions and 57 deletions
+11 -2
View File
@@ -19,7 +19,7 @@
use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{DispatchError, RuntimeDebug};
use sp_runtime::{traits::Saturating, DispatchError, RuntimeDebug};
use sp_std::{fmt::Debug, prelude::*, result::Result};
/// Information relating to the period of a scheduled task. First item is the length of the
@@ -32,7 +32,7 @@ pub type Period<BlockNumber> = (BlockNumber, u32);
pub type Priority = u8;
/// The dispatch time of a scheduled task.
#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
#[derive(Encode, Decode, Copy, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub enum DispatchTime<BlockNumber> {
/// At specified block.
At(BlockNumber),
@@ -40,6 +40,15 @@ pub enum DispatchTime<BlockNumber> {
After(BlockNumber),
}
impl<BlockNumber: Saturating + Copy> DispatchTime<BlockNumber> {
pub fn evaluate(&self, since: BlockNumber) -> BlockNumber {
match &self {
Self::At(m) => *m,
Self::After(m) => m.saturating_add(since),
}
}
}
/// The highest priority. We invert the value so that normal sorting will place the highest
/// priority at the beginning of the list.
pub const HIGHEST_PRIORITY: Priority = 0;