@@ -37,7 +37,6 @@ use frame_support::{
37
37
ReservableCurrency , WithdrawReasons ,
38
38
} ,
39
39
} ;
40
- use frame_system:: pallet_prelude:: BlockNumberFor ;
41
40
use sp_runtime:: {
42
41
traits:: { AtLeast32BitUnsigned , Saturating , StaticLookup , Zero } ,
43
42
ArithmeticError , DispatchError , Perbill ,
@@ -55,6 +54,7 @@ pub use self::{
55
54
vote:: { AccountVote , Casting , Delegating , Vote , Voting } ,
56
55
weights:: WeightInfo ,
57
56
} ;
57
+ use sp_runtime:: traits:: BlockNumberProvider ;
58
58
59
59
#[ cfg( test) ]
60
60
mod tests;
@@ -64,19 +64,22 @@ pub mod benchmarking;
64
64
65
65
const CONVICTION_VOTING_ID : LockIdentifier = * b"pyconvot" ;
66
66
67
+ pub type BlockNumberFor < T , I > =
68
+ <<T as Config < I > >:: BlockNumberProvider as BlockNumberProvider >:: BlockNumber ;
69
+
67
70
type AccountIdLookupOf < T > = <<T as frame_system:: Config >:: Lookup as StaticLookup >:: Source ;
68
71
type BalanceOf < T , I = ( ) > =
69
72
<<T as Config < I > >:: Currency as Currency < <T as frame_system:: Config >:: AccountId > >:: Balance ;
70
73
type VotingOf < T , I = ( ) > = Voting <
71
74
BalanceOf < T , I > ,
72
75
<T as frame_system:: Config >:: AccountId ,
73
- BlockNumberFor < T > ,
76
+ BlockNumberFor < T , I > ,
74
77
PollIndexOf < T , I > ,
75
78
<T as Config < I > >:: MaxVotes ,
76
79
> ;
77
80
#[ allow( dead_code) ]
78
81
type DelegatingOf < T , I = ( ) > =
79
- Delegating < BalanceOf < T , I > , <T as frame_system:: Config >:: AccountId , BlockNumberFor < T > > ;
82
+ Delegating < BalanceOf < T , I > , <T as frame_system:: Config >:: AccountId , BlockNumberFor < T , I > > ;
80
83
pub type TallyOf < T , I = ( ) > = Tally < BalanceOf < T , I > , <T as Config < I > >:: MaxTurnout > ;
81
84
pub type VotesOf < T , I = ( ) > = BalanceOf < T , I > ;
82
85
type PollIndexOf < T , I = ( ) > = <<T as Config < I > >:: Polls as Polling < TallyOf < T , I > > >:: Index ;
@@ -94,7 +97,7 @@ pub mod pallet {
94
97
traits:: ClassCountOf ,
95
98
Twox64Concat ,
96
99
} ;
97
- use frame_system:: pallet_prelude:: * ;
100
+ use frame_system:: pallet_prelude:: { ensure_signed , OriginFor } ;
98
101
use sp_runtime:: BoundedVec ;
99
102
100
103
#[ pallet:: pallet]
@@ -109,14 +112,14 @@ pub mod pallet {
109
112
type WeightInfo : WeightInfo ;
110
113
/// Currency type with which voting happens.
111
114
type Currency : ReservableCurrency < Self :: AccountId >
112
- + LockableCurrency < Self :: AccountId , Moment = BlockNumberFor < Self > >
115
+ + LockableCurrency < Self :: AccountId , Moment = BlockNumberFor < Self , I > >
113
116
+ fungible:: Inspect < Self :: AccountId > ;
114
117
115
118
/// The implementation of the logic which conducts polls.
116
119
type Polls : Polling <
117
120
TallyOf < Self , I > ,
118
121
Votes = BalanceOf < Self , I > ,
119
- Moment = BlockNumberFor < Self > ,
122
+ Moment = BlockNumberFor < Self , I > ,
120
123
> ;
121
124
122
125
/// The maximum amount of tokens which may be used for voting. May just be
@@ -136,7 +139,9 @@ pub mod pallet {
136
139
/// It should be no shorter than enactment period to ensure that in the case of an approval,
137
140
/// those successful voters are locked into the consequences that their votes entail.
138
141
#[ pallet:: constant]
139
- type VoteLockingPeriod : Get < BlockNumberFor < Self > > ;
142
+ type VoteLockingPeriod : Get < BlockNumberFor < Self , I > > ;
143
+ /// Provider for the block number. Normally this is the `frame_system` pallet.
144
+ type BlockNumberProvider : BlockNumberProvider ;
140
145
}
141
146
142
147
/// All voting for a particular voter in a particular voting class. We store the balance for the
@@ -479,7 +484,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
479
484
let unlock_at = end. saturating_add (
480
485
T :: VoteLockingPeriod :: get ( ) . saturating_mul ( lock_periods. into ( ) ) ,
481
486
) ;
482
- let now = frame_system :: Pallet :: < T > :: block_number ( ) ;
487
+ let now = T :: BlockNumberProvider :: current_block_number ( ) ;
483
488
if now < unlock_at {
484
489
ensure ! (
485
490
matches!( scope, UnvoteScope :: Any ) ,
@@ -620,7 +625,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
620
625
& class,
621
626
conviction. votes ( balance) ,
622
627
) ;
623
- let now = frame_system :: Pallet :: < T > :: block_number ( ) ;
628
+ let now = T :: BlockNumberProvider :: current_block_number ( ) ;
624
629
let lock_periods = conviction. lock_periods ( ) . into ( ) ;
625
630
prior. accumulate (
626
631
now. saturating_add (
@@ -666,7 +671,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
666
671
/// a security hole) but may be reduced from what they are currently.
667
672
fn update_lock ( class : & ClassOf < T , I > , who : & T :: AccountId ) {
668
673
let class_lock_needed = VotingFor :: < T , I > :: mutate ( who, class, |voting| {
669
- voting. rejig ( frame_system :: Pallet :: < T > :: block_number ( ) ) ;
674
+ voting. rejig ( T :: BlockNumberProvider :: current_block_number ( ) ) ;
670
675
voting. locked_balance ( )
671
676
} ) ;
672
677
let lock_needed = ClassLocksFor :: < T , I > :: mutate ( who, |locks| {
0 commit comments