@@ -271,7 +271,9 @@ use frame_support::{
271
271
} ,
272
272
PalletId ,
273
273
} ;
274
- use frame_system:: pallet_prelude:: * ;
274
+ use frame_system:: pallet_prelude:: {
275
+ ensure_signed, BlockNumberFor as SystemBlockNumberFor , OriginFor ,
276
+ } ;
275
277
use rand_chacha:: {
276
278
rand_core:: { RngCore , SeedableRng } ,
277
279
ChaChaRng ,
@@ -289,6 +291,10 @@ use sp_runtime::{
289
291
pub use weights:: WeightInfo ;
290
292
291
293
pub use pallet:: * ;
294
+ use sp_runtime:: traits:: BlockNumberProvider ;
295
+
296
+ pub type BlockNumberFor < T , I > =
297
+ <<T as Config < I > >:: BlockNumberProvider as BlockNumberProvider >:: BlockNumber ;
292
298
293
299
type BalanceOf < T , I > =
294
300
<<T as Config < I > >:: Currency as Currency < <T as frame_system:: Config >:: AccountId > >:: Balance ;
@@ -423,7 +429,7 @@ impl<AccountId: PartialEq, Balance> BidKind<AccountId, Balance> {
423
429
}
424
430
425
431
pub type PayoutsFor < T , I > =
426
- BoundedVec < ( BlockNumberFor < T > , BalanceOf < T , I > ) , <T as Config < I > >:: MaxPayouts > ;
432
+ BoundedVec < ( BlockNumberFor < T , I > , BalanceOf < T , I > ) , <T as Config < I > >:: MaxPayouts > ;
427
433
428
434
/// Information concerning a member.
429
435
#[ derive( Encode , Decode , Copy , Clone , PartialEq , Eq , RuntimeDebug , TypeInfo , MaxEncodedLen ) ]
@@ -443,7 +449,7 @@ pub struct PayoutRecord<Balance, PayoutsVec> {
443
449
444
450
pub type PayoutRecordFor < T , I > = PayoutRecord <
445
451
BalanceOf < T , I > ,
446
- BoundedVec < ( BlockNumberFor < T > , BalanceOf < T , I > ) , <T as Config < I > >:: MaxPayouts > ,
452
+ BoundedVec < ( BlockNumberFor < T , I > , BalanceOf < T , I > ) , <T as Config < I > >:: MaxPayouts > ,
447
453
> ;
448
454
449
455
/// Record for an individual new member who was elevated from a candidate recently.
@@ -491,7 +497,7 @@ pub mod pallet {
491
497
type Currency : ReservableCurrency < Self :: AccountId > ;
492
498
493
499
/// Something that provides randomness in the runtime.
494
- type Randomness : Randomness < Self :: Hash , BlockNumberFor < Self > > ;
500
+ type Randomness : Randomness < Self :: Hash , BlockNumberFor < Self , I > > ;
495
501
496
502
/// The maximum number of strikes before a member gets funds slashed.
497
503
#[ pallet:: constant]
@@ -504,23 +510,23 @@ pub mod pallet {
504
510
/// The number of blocks on which new candidates should be voted on. Together with
505
511
/// `ClaimPeriod`, this sums to the number of blocks between candidate intake periods.
506
512
#[ pallet:: constant]
507
- type VotingPeriod : Get < BlockNumberFor < Self > > ;
513
+ type VotingPeriod : Get < BlockNumberFor < Self , I > > ;
508
514
509
515
/// The number of blocks on which new candidates can claim their membership and be the
510
516
/// named head.
511
517
#[ pallet:: constant]
512
- type ClaimPeriod : Get < BlockNumberFor < Self > > ;
518
+ type ClaimPeriod : Get < BlockNumberFor < Self , I > > ;
513
519
514
520
/// The maximum duration of the payout lock.
515
521
#[ pallet:: constant]
516
- type MaxLockDuration : Get < BlockNumberFor < Self > > ;
522
+ type MaxLockDuration : Get < BlockNumberFor < Self , I > > ;
517
523
518
524
/// The origin that is allowed to call `found`.
519
525
type FounderSetOrigin : EnsureOrigin < Self :: RuntimeOrigin > ;
520
526
521
527
/// The number of blocks between membership challenges.
522
528
#[ pallet:: constant]
523
- type ChallengePeriod : Get < BlockNumberFor < Self > > ;
529
+ type ChallengePeriod : Get < SystemBlockNumberFor < Self > > ;
524
530
525
531
/// The maximum number of payouts a member may have waiting unclaimed.
526
532
#[ pallet:: constant]
@@ -532,6 +538,8 @@ pub mod pallet {
532
538
533
539
/// Weight information for extrinsics in this pallet.
534
540
type WeightInfo : WeightInfo ;
541
+ /// Provider for the block number. Normally this is the `frame_system` pallet.
542
+ type BlockNumberProvider : BlockNumberProvider ;
535
543
}
536
544
537
545
#[ pallet:: error]
@@ -757,8 +765,8 @@ pub mod pallet {
757
765
StorageDoubleMap < _ , Twox64Concat , RoundIndex , Twox64Concat , T :: AccountId , Vote > ;
758
766
759
767
#[ pallet:: hooks]
760
- impl < T : Config < I > , I : ' static > Hooks < BlockNumberFor < T > > for Pallet < T , I > {
761
- fn on_initialize ( n : BlockNumberFor < T > ) -> Weight {
768
+ impl < T : Config < I > , I : ' static > Hooks < SystemBlockNumberFor < T > > for Pallet < T , I > {
769
+ fn on_initialize ( n : SystemBlockNumberFor < T > ) -> Weight {
762
770
let mut weight = Weight :: zero ( ) ;
763
771
let weights = T :: BlockWeights :: get ( ) ;
764
772
@@ -1018,9 +1026,9 @@ pub mod pallet {
1018
1026
Error :: <T , I >:: NoPayout
1019
1027
) ;
1020
1028
let mut record = Payouts :: < T , I > :: get ( & who) ;
1021
-
1029
+ let block_number = T :: BlockNumberProvider :: current_block_number ( ) ;
1022
1030
if let Some ( ( when, amount) ) = record. payouts . first ( ) {
1023
- if when <= & <frame_system :: Pallet < T > > :: block_number ( ) {
1031
+ if when <= & block_number {
1024
1032
record. paid = record. paid . checked_add ( amount) . ok_or ( Overflow ) ?;
1025
1033
T :: Currency :: transfer ( & Self :: payouts ( ) , & who, * amount, AllowDeath ) ?;
1026
1034
record. payouts . remove ( 0 ) ;
@@ -1397,11 +1405,11 @@ pub enum Period<BlockNumber> {
1397
1405
1398
1406
impl < T : Config < I > , I : ' static > Pallet < T , I > {
1399
1407
/// Get the period we are currently in.
1400
- fn period ( ) -> Period < BlockNumberFor < T > > {
1408
+ fn period ( ) -> Period < BlockNumberFor < T , I > > {
1401
1409
let claim_period = T :: ClaimPeriod :: get ( ) ;
1402
1410
let voting_period = T :: VotingPeriod :: get ( ) ;
1403
1411
let rotation_period = voting_period + claim_period;
1404
- let now = frame_system :: Pallet :: < T > :: block_number ( ) ;
1412
+ let now = T :: BlockNumberProvider :: current_block_number ( ) ;
1405
1413
let phase = now % rotation_period;
1406
1414
if phase < voting_period {
1407
1415
Period :: Voting { elapsed : phase, more : voting_period - phase }
@@ -1728,7 +1736,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
1728
1736
} ) ;
1729
1737
NextHead :: < T , I > :: put ( next_head) ;
1730
1738
1731
- let now = <frame_system :: Pallet < T > > :: block_number ( ) ;
1739
+ let now = T :: BlockNumberProvider :: current_block_number ( ) ;
1732
1740
let maturity = now + Self :: lock_duration ( MemberCount :: < T , I > :: get ( ) ) ;
1733
1741
Self :: reward_bidder ( & candidate, candidacy. bid , candidacy. kind , maturity) ;
1734
1742
@@ -1890,7 +1898,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
1890
1898
candidate : & T :: AccountId ,
1891
1899
value : BalanceOf < T , I > ,
1892
1900
kind : BidKind < T :: AccountId , BalanceOf < T , I > > ,
1893
- maturity : BlockNumberFor < T > ,
1901
+ maturity : BlockNumberFor < T , I > ,
1894
1902
) {
1895
1903
let value = match kind {
1896
1904
BidKind :: Deposit ( deposit) => {
@@ -1927,7 +1935,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
1927
1935
///
1928
1936
/// It is the caller's duty to ensure that `who` is already a member. This does nothing if `who`
1929
1937
/// is not a member or if `value` is zero.
1930
- fn bump_payout ( who : & T :: AccountId , when : BlockNumberFor < T > , value : BalanceOf < T , I > ) {
1938
+ fn bump_payout ( who : & T :: AccountId , when : BlockNumberFor < T , I > , value : BalanceOf < T , I > ) {
1931
1939
if value. is_zero ( ) {
1932
1940
return
1933
1941
}
@@ -2010,7 +2018,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
2010
2018
///
2011
2019
/// This is a rather opaque calculation based on the formula here:
2012
2020
/// https://www.desmos.com/calculator/9itkal1tce
2013
- fn lock_duration ( x : u32 ) -> BlockNumberFor < T > {
2021
+ fn lock_duration ( x : u32 ) -> BlockNumberFor < T , I > {
2014
2022
let lock_pc = 100 - 50_000 / ( x + 500 ) ;
2015
2023
Percent :: from_percent ( lock_pc as u8 ) * T :: MaxLockDuration :: get ( )
2016
2024
}
0 commit comments