@@ -163,10 +163,10 @@ use frame_support::{
163
163
} ,
164
164
weights:: Weight ,
165
165
} ;
166
- use frame_system:: pallet_prelude:: { BlockNumberFor , OriginFor } ;
166
+ use frame_system:: pallet_prelude:: OriginFor ;
167
167
use parity_scale_codec:: { Decode , Encode } ;
168
168
use sp_runtime:: {
169
- traits:: { Bounded as ArithBounded , One , Saturating , StaticLookup , Zero } ,
169
+ traits:: { BlockNumberProvider , Bounded as ArithBounded , One , Saturating , StaticLookup , Zero } ,
170
170
ArithmeticError , DispatchError , DispatchResult ,
171
171
} ;
172
172
@@ -199,11 +199,12 @@ pub type CreditOf<T> = Credit<<T as frame_system::Config>::AccountId, <T as Conf
199
199
200
200
pub type CallOf < T > = <T as frame_system:: Config >:: RuntimeCall ;
201
201
pub type BoundedCallOf < T > = Bounded < CallOf < T > , <T as frame_system:: Config >:: Hashing > ;
202
+ pub type BlockNumberFor < T > = <<T as Config >:: BlockNumberProvider as BlockNumberProvider >:: BlockNumber ;
202
203
type AccountIdLookupOf < T > = <<T as frame_system:: Config >:: Lookup as StaticLookup >:: Source ;
203
204
204
205
#[ frame_support:: pallet]
205
206
pub mod pallet {
206
- use super :: { DispatchResult , * } ;
207
+ use super :: { BlockNumberFor , DispatchResult , * } ;
207
208
use frame_support:: {
208
209
pallet_prelude:: * ,
209
210
traits:: {
@@ -212,6 +213,7 @@ pub mod pallet {
212
213
} ,
213
214
} ;
214
215
use frame_system:: pallet_prelude:: * ;
216
+ use sp_runtime:: traits:: BlockNumberProvider ;
215
217
/// The current storage version.
216
218
const STORAGE_VERSION : StorageVersion = StorageVersion :: new ( 1 ) ;
217
219
@@ -350,6 +352,9 @@ pub mod pallet {
350
352
351
353
/// Type returning the total electorate.
352
354
type Electorate : GetElectorate < BalanceOf < Self > > ;
355
+
356
+ /// Block number provider.
357
+ type BlockNumberProvider : BlockNumberProvider < BlockNumber = frame_system:: pallet_prelude:: BlockNumberFor < Self > > ;
353
358
}
354
359
355
360
/// The number of (public) proposals that have been made so far.
@@ -610,7 +615,7 @@ pub mod pallet {
610
615
let proposal_hash = proposal. hash ( ) ;
611
616
612
617
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 , ) ;
614
619
}
615
620
616
621
T :: Fungible :: hold ( & HoldReason :: Proposal . into ( ) , & who, value) ?;
@@ -700,7 +705,7 @@ pub mod pallet {
700
705
T :: ExternalOrigin :: ensure_origin ( origin) ?;
701
706
ensure ! ( !<NextExternal <T >>:: exists( ) , Error :: <T >:: DuplicateProposal ) ;
702
707
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 , ) ;
704
709
}
705
710
<NextExternal < T > >:: put ( ( proposal, VoteThreshold :: SuperMajorityApprove ) ) ;
706
711
Ok ( ( ) )
@@ -790,7 +795,7 @@ pub mod pallet {
790
795
ensure ! ( proposal_hash == ext_proposal. hash( ) , Error :: <T >:: InvalidHash ) ;
791
796
792
797
<NextExternal < T > >:: kill ( ) ;
793
- let now = <frame_system :: Pallet < T > > :: block_number ( ) ;
798
+ let now = T :: BlockNumberProvider :: current_block_number ( ) ;
794
799
let ref_index = Self :: inject_referendum ( now. saturating_add ( voting_period) , ext_proposal, threshold, delay) ;
795
800
Self :: transfer_metadata ( MetadataOwner :: External , MetadataOwner :: Referendum ( ref_index) ) ;
796
801
Ok ( ( ) )
@@ -820,7 +825,7 @@ pub mod pallet {
820
825
let insert_position = existing_vetoers. binary_search ( & who) . err ( ) . ok_or ( Error :: < T > :: AlreadyVetoed ) ?;
821
826
existing_vetoers. try_insert ( insert_position, who. clone ( ) ) . map_err ( |_| Error :: < T > :: TooMany ) ?;
822
827
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 ( ) ) ;
824
829
<Blacklist < T > >:: insert ( & proposal_hash, ( until, existing_vetoers) ) ;
825
830
826
831
Self :: deposit_event ( Event :: < T > :: Vetoed { who, proposal_hash, until } ) ;
@@ -1196,7 +1201,7 @@ impl<T: Config> Pallet<T> {
1196
1201
delay : BlockNumberFor < T > ,
1197
1202
) -> ReferendumIndex {
1198
1203
<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 ( ) ) ,
1200
1205
proposal,
1201
1206
threshold,
1202
1207
delay,
@@ -1291,7 +1296,7 @@ impl<T: Config> Pallet<T> {
1291
1296
if let Some ( ( lock_periods, balance) ) = votes[ i] . 1 . locked_if ( approved) {
1292
1297
let unlock_at =
1293
1298
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 ( ) ;
1295
1300
if now < unlock_at {
1296
1301
ensure ! ( matches!( scope, UnvoteScope :: Any ) , Error :: <T >:: NoPermission ) ;
1297
1302
prior. accumulate ( unlock_at, balance)
@@ -1380,7 +1385,7 @@ impl<T: Config> Pallet<T> {
1380
1385
Voting :: Delegating { balance, target, conviction, delegations, mut prior, .. } => {
1381
1386
// remove any delegation votes to our current target.
1382
1387
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 ( ) ;
1384
1389
let lock_periods = conviction. lock_periods ( ) . into ( ) ;
1385
1390
let unlock_block = now. saturating_add ( T :: VoteLockingPeriod :: get ( ) . saturating_mul ( lock_periods) ) ;
1386
1391
prior. accumulate ( unlock_block, balance) ;
@@ -1413,7 +1418,7 @@ impl<T: Config> Pallet<T> {
1413
1418
Voting :: Delegating { balance, target, conviction, delegations, mut prior } => {
1414
1419
// remove any delegation votes to our current target.
1415
1420
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 ( ) ;
1417
1422
let lock_periods = conviction. lock_periods ( ) . into ( ) ;
1418
1423
let unlock_block = now. saturating_add ( T :: VoteLockingPeriod :: get ( ) . saturating_mul ( lock_periods) ) ;
1419
1424
prior. accumulate ( unlock_block, balance) ;
@@ -1432,7 +1437,7 @@ impl<T: Config> Pallet<T> {
1432
1437
/// a security hole) but may be reduced from what they are currently.
1433
1438
fn update_lock ( who : & T :: AccountId ) -> DispatchResult {
1434
1439
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 ( ) ) ;
1436
1441
voting. locked_balance ( )
1437
1442
} ) ;
1438
1443
if lock_needed. is_zero ( ) {
0 commit comments