Skip to content

Commit

Permalink
Make pallet-recovery supports BlockNumberProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier committed Nov 15, 2024
1 parent 5bc571b commit 5e6a9f8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ impl pallet_recovery::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type RuntimeCall = RuntimeCall;
type BlockNumberProvider = System;
type Currency = Balances;
type ConfigDepositBase = ConfigDepositBase;
type FriendDepositFactor = FriendDepositFactor;
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ impl pallet_recovery::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type RuntimeCall = RuntimeCall;
type BlockNumberProvider = System;
type Currency = Balances;
type ConfigDepositBase = ConfigDepositBase;
type FriendDepositFactor = FriendDepositFactor;
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,7 @@ impl pallet_recovery::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_recovery::weights::SubstrateWeight<Runtime>;
type RuntimeCall = RuntimeCall;
type BlockNumberProvider = System;
type Currency = Balances;
type ConfigDepositBase = ConfigDepositBase;
type FriendDepositFactor = FriendDepositFactor;
Expand Down
12 changes: 9 additions & 3 deletions substrate/frame/recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ use alloc::{boxed::Box, vec::Vec};
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{CheckedAdd, CheckedMul, Dispatchable, SaturatedConversion, StaticLookup},
traits::{
BlockNumberProvider, CheckedAdd, CheckedMul, Dispatchable, SaturatedConversion,
StaticLookup,
},
RuntimeDebug,
};

Expand Down Expand Up @@ -236,6 +239,9 @@ pub mod pallet {
+ GetDispatchInfo
+ From<frame_system::Call<Self>>;

/// Provider for the block number. Normally this is the `frame_system` pallet.
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;

/// The currency mechanism.
type Currency: ReservableCurrency<Self::AccountId>;

Expand Down Expand Up @@ -511,7 +517,7 @@ pub mod pallet {
T::Currency::reserve(&who, recovery_deposit)?;
// Create an active recovery status
let recovery_status = ActiveRecovery {
created: <frame_system::Pallet<T>>::block_number(),
created: T::BlockNumberProvider::current_block_number(),
deposit: recovery_deposit,
friends: Default::default(),
};
Expand Down Expand Up @@ -596,7 +602,7 @@ pub mod pallet {
Self::active_recovery(&account, &who).ok_or(Error::<T>::NotStarted)?;
ensure!(!Proxy::<T>::contains_key(&who), Error::<T>::AlreadyProxy);
// Make sure the delay period has passed
let current_block_number = <frame_system::Pallet<T>>::block_number();
let current_block_number = T::BlockNumberProvider::current_block_number();
let recoverable_block_number = active_recovery
.created
.checked_add(&recovery_config.delay_period)
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/recovery/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type RuntimeCall = RuntimeCall;
type BlockNumberProvider = System;
type Currency = Balances;
type ConfigDepositBase = ConfigDepositBase;
type FriendDepositFactor = FriendDepositFactor;
Expand Down

0 comments on commit 5e6a9f8

Please sign in to comment.