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
@@ -59,6 +59,18 @@ pub trait Currency<AccountId> {
/// The total amount of issuance in the system.
fn total_issuance() -> Self::Balance;
/// The total amount of issuance in the system excluding those which are controlled by the
/// system.
fn active_issuance() -> Self::Balance {
Self::total_issuance()
}
/// Reduce the active issuance by some amount.
fn deactivate(_: Self::Balance) {}
/// Increase the active issuance by some amount, up to the outstanding amount reduced.
fn reactivate(_: Self::Balance) {}
/// The minimum balance any single account may have. This is equivalent to the `Balances`
/// module's `ExistentialDeposit`.
fn minimum_balance() -> Self::Balance;
@@ -212,6 +224,15 @@ impl<C: Currency<A>, A> Get<C::Balance> for TotalIssuanceOf<C, A> {
}
}
/// A non-const `Get` implementation parameterised by a `Currency` impl which provides the result
/// of `active_issuance`.
pub struct ActiveIssuanceOf<C: Currency<A>, A>(sp_std::marker::PhantomData<(C, A)>);
impl<C: Currency<A>, A> Get<C::Balance> for ActiveIssuanceOf<C, A> {
fn get() -> C::Balance {
C::active_issuance()
}
}
#[cfg(feature = "std")]
impl<AccountId> Currency<AccountId> for () {
type Balance = u32;
@@ -40,6 +40,12 @@ pub trait Inspect<AccountId> {
/// The total amount of issuance in the system.
fn total_issuance() -> Self::Balance;
/// The total amount of issuance in the system excluding those which are controlled by the
/// system.
fn active_issuance() -> Self::Balance {
Self::total_issuance()
}
/// The minimum balance any single account may have.
fn minimum_balance() -> Self::Balance;
@@ -120,6 +126,12 @@ pub trait Transfer<AccountId>: Inspect<AccountId> {
amount: Self::Balance,
keep_alive: bool,
) -> Result<Self::Balance, DispatchError>;
/// Reduce the active issuance by some amount.
fn deactivate(_: Self::Balance) {}
/// Increase the active issuance by some amount, up to the outstanding amount reduced.
fn reactivate(_: Self::Balance) {}
}
/// Trait for inspecting a fungible asset which can be reserved.
@@ -213,6 +225,9 @@ impl<
fn total_issuance() -> Self::Balance {
<F as fungibles::Inspect<AccountId>>::total_issuance(A::get())
}
fn active_issuance() -> Self::Balance {
<F as fungibles::Inspect<AccountId>>::active_issuance(A::get())
}
fn minimum_balance() -> Self::Balance {
<F as fungibles::Inspect<AccountId>>::minimum_balance(A::get())
}
@@ -258,6 +273,12 @@ impl<
) -> Result<Self::Balance, DispatchError> {
<F as fungibles::Transfer<AccountId>>::transfer(A::get(), source, dest, amount, keep_alive)
}
fn deactivate(amount: Self::Balance) {
<F as fungibles::Transfer<AccountId>>::deactivate(A::get(), amount)
}
fn reactivate(amount: Self::Balance) {
<F as fungibles::Transfer<AccountId>>::reactivate(A::get(), amount)
}
}
impl<
@@ -46,6 +46,12 @@ pub trait Inspect<AccountId> {
/// The total amount of issuance in the system.
fn total_issuance(asset: Self::AssetId) -> Self::Balance;
/// The total amount of issuance in the system excluding those which are controlled by the
/// system.
fn active_issuance(asset: Self::AssetId) -> Self::Balance {
Self::total_issuance(asset)
}
/// The minimum balance any single account may have.
fn minimum_balance(asset: Self::AssetId) -> Self::Balance;
@@ -177,6 +183,12 @@ pub trait Transfer<AccountId>: Inspect<AccountId> {
amount: Self::Balance,
keep_alive: bool,
) -> Result<Self::Balance, DispatchError>;
/// Reduce the active issuance by some amount.
fn deactivate(_: Self::AssetId, _: Self::Balance) {}
/// Increase the active issuance by some amount, up to the outstanding amount reduced.
fn reactivate(_: Self::AssetId, _: Self::Balance) {}
}
/// Trait for inspecting a set of named fungible assets which can be placed on hold.