@@ -163,10 +163,10 @@ use frame_support::{
163163 } ,
164164 weights:: Weight ,
165165} ;
166- use frame_system:: pallet_prelude:: { BlockNumberFor , OriginFor } ;
166+ use frame_system:: pallet_prelude:: OriginFor ;
167167use parity_scale_codec:: { Decode , Encode } ;
168168use sp_runtime:: {
169- traits:: { Bounded as ArithBounded , One , Saturating , StaticLookup , Zero } ,
169+ traits:: { BlockNumberProvider , Bounded as ArithBounded , One , Saturating , StaticLookup , Zero } ,
170170 ArithmeticError , DispatchError , DispatchResult ,
171171} ;
172172
@@ -199,11 +199,12 @@ pub type CreditOf<T> = Credit<<T as frame_system::Config>::AccountId, <T as Conf
199199
200200pub type CallOf < T > = <T as frame_system:: Config >:: RuntimeCall ;
201201pub type BoundedCallOf < T > = Bounded < CallOf < T > , <T as frame_system:: Config >:: Hashing > ;
202+ pub type BlockNumberFor < T > = <<T as Config >:: BlockNumberProvider as BlockNumberProvider >:: BlockNumber ;
202203type AccountIdLookupOf < T > = <<T as frame_system:: Config >:: Lookup as StaticLookup >:: Source ;
203204
204205#[ frame_support:: pallet]
205206pub mod pallet {
206- use super :: { DispatchResult , * } ;
207+ use super :: { BlockNumberFor , DispatchResult , * } ;
207208 use frame_support:: {
208209 pallet_prelude:: * ,
209210 traits:: {
@@ -212,6 +213,7 @@ pub mod pallet {
212213 } ,
213214 } ;
214215 use frame_system:: pallet_prelude:: * ;
216+ use sp_runtime:: traits:: BlockNumberProvider ;
215217 /// The current storage version.
216218 const STORAGE_VERSION : StorageVersion = StorageVersion :: new ( 1 ) ;
217219
@@ -350,6 +352,9 @@ pub mod pallet {
350352
351353 /// Type returning the total electorate.
352354 type Electorate : GetElectorate < BalanceOf < Self > > ;
355+
356+ /// Block number provider.
357+ type BlockNumberProvider : BlockNumberProvider < BlockNumber = frame_system:: pallet_prelude:: BlockNumberFor < Self > > ;
353358 }
354359
355360 /// The number of (public) proposals that have been made so far.
@@ -610,7 +615,7 @@ pub mod pallet {
610615 let proposal_hash = proposal. hash ( ) ;
611616
612617 if let Some ( ( until, _) ) = <Blacklist < T > >:: get ( proposal_hash) {
613- ensure ! ( <frame_system :: Pallet < T >> :: block_number ( ) >= until, Error :: <T >:: ProposalBlacklisted , ) ;
618+ ensure ! ( T :: BlockNumberProvider :: current_block_number ( ) >= until, Error :: <T >:: ProposalBlacklisted , ) ;
614619 }
615620
616621 T :: Fungible :: hold ( & HoldReason :: Proposal . into ( ) , & who, value) ?;
@@ -700,7 +705,7 @@ pub mod pallet {
700705 T :: ExternalOrigin :: ensure_origin ( origin) ?;
701706 ensure ! ( !<NextExternal <T >>:: exists( ) , Error :: <T >:: DuplicateProposal ) ;
702707 if let Some ( ( until, _) ) = <Blacklist < T > >:: get ( proposal. hash ( ) ) {
703- ensure ! ( <frame_system :: Pallet < T >> :: block_number ( ) >= until, Error :: <T >:: ProposalBlacklisted , ) ;
708+ ensure ! ( T :: BlockNumberProvider :: current_block_number ( ) >= until, Error :: <T >:: ProposalBlacklisted , ) ;
704709 }
705710 <NextExternal < T > >:: put ( ( proposal, VoteThreshold :: SuperMajorityApprove ) ) ;
706711 Ok ( ( ) )
@@ -790,7 +795,7 @@ pub mod pallet {
790795 ensure ! ( proposal_hash == ext_proposal. hash( ) , Error :: <T >:: InvalidHash ) ;
791796
792797 <NextExternal < T > >:: kill ( ) ;
793- let now = <frame_system :: Pallet < T > > :: block_number ( ) ;
798+ let now = T :: BlockNumberProvider :: current_block_number ( ) ;
794799 let ref_index = Self :: inject_referendum ( now. saturating_add ( voting_period) , ext_proposal, threshold, delay) ;
795800 Self :: transfer_metadata ( MetadataOwner :: External , MetadataOwner :: Referendum ( ref_index) ) ;
796801 Ok ( ( ) )
@@ -820,7 +825,7 @@ pub mod pallet {
820825 let insert_position = existing_vetoers. binary_search ( & who) . err ( ) . ok_or ( Error :: < T > :: AlreadyVetoed ) ?;
821826 existing_vetoers. try_insert ( insert_position, who. clone ( ) ) . map_err ( |_| Error :: < T > :: TooMany ) ?;
822827
823- let until = <frame_system :: Pallet < T > > :: block_number ( ) . saturating_add ( T :: CooloffPeriod :: get ( ) ) ;
828+ let until = T :: BlockNumberProvider :: current_block_number ( ) . saturating_add ( T :: CooloffPeriod :: get ( ) ) ;
824829 <Blacklist < T > >:: insert ( & proposal_hash, ( until, existing_vetoers) ) ;
825830
826831 Self :: deposit_event ( Event :: < T > :: Vetoed { who, proposal_hash, until } ) ;
@@ -1196,7 +1201,7 @@ impl<T: Config> Pallet<T> {
11961201 delay : BlockNumberFor < T > ,
11971202 ) -> ReferendumIndex {
11981203 <Pallet < T > >:: inject_referendum (
1199- <frame_system :: Pallet < T > > :: block_number ( ) . saturating_add ( T :: VotingPeriod :: get ( ) ) ,
1204+ T :: BlockNumberProvider :: current_block_number ( ) . saturating_add ( T :: VotingPeriod :: get ( ) ) ,
12001205 proposal,
12011206 threshold,
12021207 delay,
@@ -1291,7 +1296,7 @@ impl<T: Config> Pallet<T> {
12911296 if let Some ( ( lock_periods, balance) ) = votes[ i] . 1 . locked_if ( approved) {
12921297 let unlock_at =
12931298 end. saturating_add ( T :: VoteLockingPeriod :: get ( ) . saturating_mul ( lock_periods. into ( ) ) ) ;
1294- let now = frame_system :: Pallet :: < T > :: block_number ( ) ;
1299+ let now = T :: BlockNumberProvider :: current_block_number ( ) ;
12951300 if now < unlock_at {
12961301 ensure ! ( matches!( scope, UnvoteScope :: Any ) , Error :: <T >:: NoPermission ) ;
12971302 prior. accumulate ( unlock_at, balance)
@@ -1380,7 +1385,7 @@ impl<T: Config> Pallet<T> {
13801385 Voting :: Delegating { balance, target, conviction, delegations, mut prior, .. } => {
13811386 // remove any delegation votes to our current target.
13821387 Self :: reduce_upstream_delegation ( & target, conviction. votes ( balance) ) ;
1383- let now = frame_system :: Pallet :: < T > :: block_number ( ) ;
1388+ let now = T :: BlockNumberProvider :: current_block_number ( ) ;
13841389 let lock_periods = conviction. lock_periods ( ) . into ( ) ;
13851390 let unlock_block = now. saturating_add ( T :: VoteLockingPeriod :: get ( ) . saturating_mul ( lock_periods) ) ;
13861391 prior. accumulate ( unlock_block, balance) ;
@@ -1413,7 +1418,7 @@ impl<T: Config> Pallet<T> {
14131418 Voting :: Delegating { balance, target, conviction, delegations, mut prior } => {
14141419 // remove any delegation votes to our current target.
14151420 let votes = Self :: reduce_upstream_delegation ( & target, conviction. votes ( balance) ) ;
1416- let now = frame_system :: Pallet :: < T > :: block_number ( ) ;
1421+ let now = T :: BlockNumberProvider :: current_block_number ( ) ;
14171422 let lock_periods = conviction. lock_periods ( ) . into ( ) ;
14181423 let unlock_block = now. saturating_add ( T :: VoteLockingPeriod :: get ( ) . saturating_mul ( lock_periods) ) ;
14191424 prior. accumulate ( unlock_block, balance) ;
@@ -1432,7 +1437,7 @@ impl<T: Config> Pallet<T> {
14321437 /// a security hole) but may be reduced from what they are currently.
14331438 fn update_lock ( who : & T :: AccountId ) -> DispatchResult {
14341439 let lock_needed = VotingOf :: < T > :: mutate ( who, |voting| {
1435- voting. rejig ( frame_system :: Pallet :: < T > :: block_number ( ) ) ;
1440+ voting. rejig ( T :: BlockNumberProvider :: current_block_number ( ) ) ;
14361441 voting. locked_balance ( )
14371442 } ) ;
14381443 if lock_needed. is_zero ( ) {
0 commit comments