mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 11:51:01 +00:00
[FRAME] Introduce force_adjust_total_issuance (#3001)
Add `Balances::force_adjust_total_issuance` as preparation for fixing https://github.com/polkadot-fellows/runtimes/issues/147. Important changes in `substrate/frame/balances/src/lib.rs`. TODO: - [x] Update weights --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: command-bot <> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
committed by
GitHub
parent
4220503d28
commit
5a6f6d33d3
@@ -190,7 +190,8 @@ use sp_runtime::{
|
||||
};
|
||||
use sp_std::{cmp, fmt::Debug, mem, prelude::*, result};
|
||||
pub use types::{
|
||||
AccountData, BalanceLock, DustCleaner, ExtraFlags, IdAmount, Reasons, ReserveData,
|
||||
AccountData, AdjustmentDirection, BalanceLock, DustCleaner, ExtraFlags, IdAmount, Reasons,
|
||||
ReserveData,
|
||||
};
|
||||
pub use weights::WeightInfo;
|
||||
|
||||
@@ -384,6 +385,8 @@ pub mod pallet {
|
||||
Frozen { who: T::AccountId, amount: T::Balance },
|
||||
/// Some balance was thawed.
|
||||
Thawed { who: T::AccountId, amount: T::Balance },
|
||||
/// The `TotalIssuance` was forcefully changed.
|
||||
TotalIssuanceForced { old: T::Balance, new: T::Balance },
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
@@ -408,6 +411,10 @@ pub mod pallet {
|
||||
TooManyHolds,
|
||||
/// Number of freezes exceed `MaxFreezes`.
|
||||
TooManyFreezes,
|
||||
/// The issuance cannot be modified since it is already deactivated.
|
||||
IssuanceDeactivated,
|
||||
/// The delta cannot be zero.
|
||||
DeltaZero,
|
||||
}
|
||||
|
||||
/// The total units issued in the system.
|
||||
@@ -743,6 +750,37 @@ pub mod pallet {
|
||||
Self::deposit_event(Event::BalanceSet { who, free: new_free });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Adjust the total issuance in a saturating way.
|
||||
///
|
||||
/// Can only be called by root and always needs a positive `delta`.
|
||||
///
|
||||
/// # Example
|
||||
#[doc = docify::embed!("./src/tests/dispatchable_tests.rs", force_adjust_total_issuance_example)]
|
||||
#[pallet::call_index(9)]
|
||||
#[pallet::weight(T::WeightInfo::force_adjust_total_issuance())]
|
||||
pub fn force_adjust_total_issuance(
|
||||
origin: OriginFor<T>,
|
||||
direction: AdjustmentDirection,
|
||||
#[pallet::compact] delta: T::Balance,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
|
||||
ensure!(delta > Zero::zero(), Error::<T, I>::DeltaZero);
|
||||
|
||||
let old = TotalIssuance::<T, I>::get();
|
||||
let new = match direction {
|
||||
AdjustmentDirection::Increase => old.saturating_add(delta),
|
||||
AdjustmentDirection::Decrease => old.saturating_sub(delta),
|
||||
};
|
||||
|
||||
ensure!(InactiveIssuance::<T, I>::get() <= new, Error::<T, I>::IssuanceDeactivated);
|
||||
TotalIssuance::<T, I>::set(new);
|
||||
|
||||
Self::deposit_event(Event::<T, I>::TotalIssuanceForced { old, new });
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
|
||||
Reference in New Issue
Block a user