mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 15:11:02 +00:00
pallet-vesting: Configurable block number provider (#2403)
This PR makes the block number provider configurable through the Config trait in pallet-vesting, this gives parachains the option to use the relay chain block number provider from ParachainSystem. --------- Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
committed by
GitHub
parent
50b7b6f399
commit
c2d45e7e47
@@ -71,8 +71,8 @@ use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use scale_info::TypeInfo;
|
||||
use sp_runtime::{
|
||||
traits::{
|
||||
AtLeast32BitUnsigned, Bounded, Convert, MaybeSerializeDeserialize, One, Saturating,
|
||||
StaticLookup, Zero,
|
||||
AtLeast32BitUnsigned, BlockNumberProvider, Bounded, Convert, MaybeSerializeDeserialize,
|
||||
One, Saturating, StaticLookup, Zero,
|
||||
},
|
||||
DispatchError, RuntimeDebug,
|
||||
};
|
||||
@@ -176,6 +176,9 @@ pub mod pallet {
|
||||
/// the unvested amount.
|
||||
type UnvestedFundsAllowedWithdrawReasons: Get<WithdrawReasons>;
|
||||
|
||||
/// Provider for the block number.
|
||||
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
|
||||
|
||||
/// Maximum number of vesting schedules an account may have at a given moment.
|
||||
const MAX_VESTING_SCHEDULES: u32;
|
||||
}
|
||||
@@ -565,7 +568,7 @@ impl<T: Config> Pallet<T> {
|
||||
schedules: Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>,
|
||||
action: VestingAction,
|
||||
) -> (Vec<VestingInfo<BalanceOf<T>, BlockNumberFor<T>>>, BalanceOf<T>) {
|
||||
let now = <frame_system::Pallet<T>>::block_number();
|
||||
let now = T::BlockNumberProvider::current_block_number();
|
||||
|
||||
let mut total_locked_now: BalanceOf<T> = Zero::zero();
|
||||
let filtered_schedules = action
|
||||
@@ -649,7 +652,7 @@ impl<T: Config> Pallet<T> {
|
||||
let (mut schedules, mut locked_now) =
|
||||
Self::report_schedule_updates(schedules.to_vec(), action);
|
||||
|
||||
let now = <frame_system::Pallet<T>>::block_number();
|
||||
let now = T::BlockNumberProvider::current_block_number();
|
||||
if let Some(new_schedule) = Self::merge_vesting_info(now, schedule1, schedule2) {
|
||||
// Merging created a new schedule so we:
|
||||
// 1) need to add it to the accounts vesting schedule collection,
|
||||
@@ -685,7 +688,7 @@ where
|
||||
/// Get the amount that is currently being vested and cannot be transferred out of this account.
|
||||
fn vesting_balance(who: &T::AccountId) -> Option<BalanceOf<T>> {
|
||||
if let Some(v) = Self::vesting(who) {
|
||||
let now = <frame_system::Pallet<T>>::block_number();
|
||||
let now = T::BlockNumberProvider::current_block_number();
|
||||
let total_locked_now = v.iter().fold(Zero::zero(), |total, schedule| {
|
||||
schedule.locked_at::<T::BlockNumberToBalance>(now).saturating_add(total)
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user