@@ -156,7 +156,10 @@ use alloc::{boxed::Box, vec::Vec};
156
156
use codec:: { Decode , Encode , MaxEncodedLen } ;
157
157
use scale_info:: TypeInfo ;
158
158
use sp_runtime:: {
159
- traits:: { CheckedAdd , CheckedMul , Dispatchable , SaturatedConversion , StaticLookup } ,
159
+ traits:: {
160
+ BlockNumberProvider , CheckedAdd , CheckedMul , Dispatchable , SaturatedConversion ,
161
+ StaticLookup ,
162
+ } ,
160
163
RuntimeDebug ,
161
164
} ;
162
165
@@ -178,19 +181,20 @@ mod mock;
178
181
mod tests;
179
182
pub mod weights;
180
183
184
+ type AccountIdLookupOf < T > = <<T as frame_system:: Config >:: Lookup as StaticLookup >:: Source ;
181
185
type BalanceOf < T > =
182
186
<<T as Config >:: Currency as Currency < <T as frame_system:: Config >:: AccountId > >:: Balance ;
183
-
187
+ type BlockNumberFromProviderOf < T > =
188
+ <<T as Config >:: BlockNumberProvider as BlockNumberProvider >:: BlockNumber ;
184
189
type FriendsOf < T > = BoundedVec < <T as frame_system:: Config >:: AccountId , <T as Config >:: MaxFriends > ;
185
- type AccountIdLookupOf < T > = <<T as frame_system:: Config >:: Lookup as StaticLookup >:: Source ;
186
190
187
191
/// An active recovery process.
188
192
#[ derive( Clone , Eq , PartialEq , Encode , Decode , Default , RuntimeDebug , TypeInfo , MaxEncodedLen ) ]
189
193
pub struct ActiveRecovery < BlockNumber , Balance , Friends > {
190
194
/// The block number when the recovery process started.
191
195
created : BlockNumber ,
192
196
/// The amount held in reserve of the `depositor`,
193
- /// To be returned once this recovery process is closed.
197
+ /// to be returned once this recovery process is closed.
194
198
deposit : Balance ,
195
199
/// The friends which have vouched so far. Always sorted.
196
200
friends : Friends ,
@@ -236,6 +240,9 @@ pub mod pallet {
236
240
+ GetDispatchInfo
237
241
+ From < frame_system:: Call < Self > > ;
238
242
243
+ /// Provider for the block number. Normally this is the `frame_system` pallet.
244
+ type BlockNumberProvider : BlockNumberProvider ;
245
+
239
246
/// The currency mechanism.
240
247
type Currency : ReservableCurrency < Self :: AccountId > ;
241
248
@@ -339,7 +346,7 @@ pub mod pallet {
339
346
_ ,
340
347
Twox64Concat ,
341
348
T :: AccountId ,
342
- RecoveryConfig < BlockNumberFor < T > , BalanceOf < T > , FriendsOf < T > > ,
349
+ RecoveryConfig < BlockNumberFromProviderOf < T > , BalanceOf < T > , FriendsOf < T > > ,
343
350
> ;
344
351
345
352
/// Active recovery attempts.
@@ -354,7 +361,7 @@ pub mod pallet {
354
361
T :: AccountId ,
355
362
Twox64Concat ,
356
363
T :: AccountId ,
357
- ActiveRecovery < BlockNumberFor < T > , BalanceOf < T > , FriendsOf < T > > ,
364
+ ActiveRecovery < BlockNumberFromProviderOf < T > , BalanceOf < T > , FriendsOf < T > > ,
358
365
> ;
359
366
360
367
/// The list of allowed proxy accounts.
@@ -445,7 +452,7 @@ pub mod pallet {
445
452
origin : OriginFor < T > ,
446
453
friends : Vec < T :: AccountId > ,
447
454
threshold : u16 ,
448
- delay_period : BlockNumberFor < T > ,
455
+ delay_period : BlockNumberFromProviderOf < T > ,
449
456
) -> DispatchResult {
450
457
let who = ensure_signed ( origin) ?;
451
458
// Check account is not already set up for recovery
@@ -511,7 +518,7 @@ pub mod pallet {
511
518
T :: Currency :: reserve ( & who, recovery_deposit) ?;
512
519
// Create an active recovery status
513
520
let recovery_status = ActiveRecovery {
514
- created : <frame_system :: Pallet < T > > :: block_number ( ) ,
521
+ created : T :: BlockNumberProvider :: current_block_number ( ) ,
515
522
deposit : recovery_deposit,
516
523
friends : Default :: default ( ) ,
517
524
} ;
@@ -596,7 +603,7 @@ pub mod pallet {
596
603
Self :: active_recovery ( & account, & who) . ok_or ( Error :: < T > :: NotStarted ) ?;
597
604
ensure ! ( !Proxy :: <T >:: contains_key( & who) , Error :: <T >:: AlreadyProxy ) ;
598
605
// Make sure the delay period has passed
599
- let current_block_number = <frame_system :: Pallet < T > > :: block_number ( ) ;
606
+ let current_block_number = T :: BlockNumberProvider :: current_block_number ( ) ;
600
607
let recoverable_block_number = active_recovery
601
608
. created
602
609
. checked_add ( & recovery_config. delay_period )
0 commit comments