@@ -61,7 +61,7 @@ use codec::{Decode, Encode, MaxEncodedLen};
6161use scale_info:: TypeInfo ;
6262use sp_arithmetic:: traits:: { Saturating , Zero } ;
6363use sp_runtime:: RuntimeDebug ;
64- use sp_std:: { marker:: PhantomData , prelude:: * } ;
64+ use sp_std:: { fmt :: Debug , marker:: PhantomData , prelude:: * } ;
6565
6666use frame_support:: {
6767 defensive,
@@ -71,18 +71,19 @@ use frame_support::{
7171 tokens:: Balance as BalanceTrait , EnsureOrigin , EnsureOriginWithArg , Get , RankedMembers ,
7272 RankedMembersSwapHandler ,
7373 } ,
74- BoundedVec ,
74+ BoundedVec , CloneNoBound , EqNoBound , PartialEqNoBound , RuntimeDebugNoBound ,
7575} ;
7676
7777#[ cfg( test) ]
7878mod tests;
7979
8080#[ cfg( feature = "runtime-benchmarks" ) ]
8181mod benchmarking;
82+ pub mod migration;
8283pub mod weights;
8384
8485pub use pallet:: * ;
85- pub use weights:: WeightInfo ;
86+ pub use weights:: * ;
8687
8788/// The desired outcome for which evidence is presented.
8889#[ derive( Encode , Decode , Eq , PartialEq , Copy , Clone , TypeInfo , MaxEncodedLen , RuntimeDebug ) ]
@@ -100,29 +101,46 @@ pub enum Wish {
100101pub type Evidence < T , I > = BoundedVec < u8 , <T as Config < I > >:: EvidenceSize > ;
101102
102103/// The status of the pallet instance.
103- #[ derive( Encode , Decode , Eq , PartialEq , Clone , TypeInfo , MaxEncodedLen , RuntimeDebug ) ]
104- pub struct ParamsType < Balance , BlockNumber , const RANKS : usize > {
104+ #[ derive(
105+ Encode ,
106+ Decode ,
107+ CloneNoBound ,
108+ EqNoBound ,
109+ PartialEqNoBound ,
110+ RuntimeDebugNoBound ,
111+ TypeInfo ,
112+ MaxEncodedLen ,
113+ ) ]
114+ #[ scale_info( skip_type_params( Ranks ) ) ]
115+ pub struct ParamsType <
116+ Balance : Clone + Eq + PartialEq + Debug ,
117+ BlockNumber : Clone + Eq + PartialEq + Debug ,
118+ Ranks : Get < u32 > ,
119+ > {
105120 /// The amounts to be paid when a member of a given rank (-1) is active.
106- active_salary : [ Balance ; RANKS ] ,
121+ pub active_salary : BoundedVec < Balance , Ranks > ,
107122 /// The amounts to be paid when a member of a given rank (-1) is passive.
108- passive_salary : [ Balance ; RANKS ] ,
123+ pub passive_salary : BoundedVec < Balance , Ranks > ,
109124 /// The period between which unproven members become demoted.
110- demotion_period : [ BlockNumber ; RANKS ] ,
125+ pub demotion_period : BoundedVec < BlockNumber , Ranks > ,
111126 /// The period between which members must wait before they may proceed to this rank.
112- min_promotion_period : [ BlockNumber ; RANKS ] ,
127+ pub min_promotion_period : BoundedVec < BlockNumber , Ranks > ,
113128 /// Amount by which an account can remain at rank 0 (candidate before being offboard entirely).
114- offboard_timeout : BlockNumber ,
129+ pub offboard_timeout : BlockNumber ,
115130}
116131
117- impl < Balance : Default + Copy , BlockNumber : Default + Copy , const RANKS : usize > Default
118- for ParamsType < Balance , BlockNumber , RANKS >
132+ impl <
133+ Balance : Default + Copy + Eq + Debug ,
134+ BlockNumber : Default + Copy + Eq + Debug ,
135+ Ranks : Get < u32 > ,
136+ > Default for ParamsType < Balance , BlockNumber , Ranks >
119137{
120138 fn default ( ) -> Self {
121139 Self {
122- active_salary : [ Balance :: default ( ) ; RANKS ] ,
123- passive_salary : [ Balance :: default ( ) ; RANKS ] ,
124- demotion_period : [ BlockNumber :: default ( ) ; RANKS ] ,
125- min_promotion_period : [ BlockNumber :: default ( ) ; RANKS ] ,
140+ active_salary : Default :: default ( ) ,
141+ passive_salary : Default :: default ( ) ,
142+ demotion_period : Default :: default ( ) ,
143+ min_promotion_period : Default :: default ( ) ,
126144 offboard_timeout : BlockNumber :: default ( ) ,
127145 }
128146 }
@@ -148,11 +166,11 @@ pub mod pallet {
148166 traits:: { tokens:: GetSalary , EnsureOrigin } ,
149167 } ;
150168 use frame_system:: { ensure_root, pallet_prelude:: * } ;
151-
152- /// Number of available ranks.
153- pub ( crate ) const RANK_COUNT : usize = 9 ;
169+ /// The in-code storage version.
170+ const STORAGE_VERSION : StorageVersion = StorageVersion :: new ( 1 ) ;
154171
155172 #[ pallet:: pallet]
173+ #[ pallet:: storage_version( STORAGE_VERSION ) ]
156174 pub struct Pallet < T , I = ( ) > ( PhantomData < ( T , I ) > ) ;
157175
158176 #[ pallet:: config]
@@ -194,9 +212,16 @@ pub mod pallet {
194212 /// The maximum size in bytes submitted evidence is allowed to be.
195213 #[ pallet:: constant]
196214 type EvidenceSize : Get < u32 > ;
215+
216+ /// Represents the highest possible rank in this pallet.
217+ ///
218+ /// Increasing this value is supported, but decreasing it may lead to a broken state.
219+ #[ pallet:: constant]
220+ type MaxRank : Get < u32 > ;
197221 }
198222
199- pub type ParamsOf < T , I > = ParamsType < <T as Config < I > >:: Balance , BlockNumberFor < T > , RANK_COUNT > ;
223+ pub type ParamsOf < T , I > =
224+ ParamsType < <T as Config < I > >:: Balance , BlockNumberFor < T > , <T as Config < I > >:: MaxRank > ;
200225 pub type MemberStatusOf < T > = MemberStatus < BlockNumberFor < T > > ;
201226 pub type RankOf < T , I > = <<T as Config < I > >:: Members as RankedMembers >:: Rank ;
202227
@@ -338,8 +363,10 @@ pub mod pallet {
338363 #[ pallet:: call_index( 1 ) ]
339364 pub fn set_params ( origin : OriginFor < T > , params : Box < ParamsOf < T , I > > ) -> DispatchResult {
340365 T :: ParamsOrigin :: ensure_origin_or_root ( origin) ?;
366+
341367 Params :: < T , I > :: put ( params. as_ref ( ) ) ;
342368 Self :: deposit_event ( Event :: < T , I > :: ParamsChanged { params : * params } ) ;
369+
343370 Ok ( ( ) )
344371 }
345372
@@ -540,7 +567,7 @@ pub mod pallet {
540567 /// in the range `1..=RANK_COUNT` is `None`.
541568 pub ( crate ) fn rank_to_index ( rank : RankOf < T , I > ) -> Option < usize > {
542569 match TryInto :: < usize > :: try_into ( rank) {
543- Ok ( r) if r <= RANK_COUNT && r > 0 => Some ( r - 1 ) ,
570+ Ok ( r) if r as u32 <= < T as Config < I > > :: MaxRank :: get ( ) && r > 0 => Some ( r - 1 ) ,
544571 _ => return None ,
545572 }
546573 }
0 commit comments