API for registering inactive funds (#12813)

* API for registering inactive funds

* Build fixes.

* Update frame/treasury/src/lib.rs

* Fix

* Fixes

* Fixes
This commit is contained in:
Gavin Wood
2022-12-03 09:14:47 +01:00
committed by GitHub
parent 3af87703de
commit d3fc468ad0
6 changed files with 151 additions and 1 deletions
+14
View File
@@ -223,6 +223,10 @@ pub mod pallet {
OptionQuery,
>;
/// The amount which has been reported as inactive to Currency.
#[pallet::storage]
pub type Inactive<T: Config<I>, I: 'static = ()> = StorageValue<_, BalanceOf<T, I>, ValueQuery>;
/// Proposal indices that have been approved but not yet awarded.
#[pallet::storage]
#[pallet::getter(fn approvals)]
@@ -316,6 +320,16 @@ pub mod pallet {
/// - The weight is overestimated if some approvals got missed.
/// # </weight>
fn on_initialize(n: T::BlockNumber) -> Weight {
let pot = Self::pot();
let deactivated = Inactive::<T, I>::get();
if pot != deactivated {
match (pot > deactivated, pot.max(deactivated) - pot.min(deactivated)) {
(true, delta) => T::Currency::deactivate(delta),
(false, delta) => T::Currency::reactivate(delta),
}
Inactive::<T, I>::put(&pot);
}
// Check to see if we should spend some funds!
if (n % T::SpendPeriod::get()).is_zero() {
Self::spend_funds()