Trait frame_support::traits::tokens::fungibles::Balanced [−][src]
pub trait Balanced<AccountId>: Inspect<AccountId> { type OnDropDebt: HandleImbalanceDrop<Self::AssetId, Self::Balance>; type OnDropCredit: HandleImbalanceDrop<Self::AssetId, Self::Balance>; fn rescind(
asset: Self::AssetId,
amount: Self::Balance
) -> DebtOf<AccountId, Self>; fn issue(
asset: Self::AssetId,
amount: Self::Balance
) -> CreditOf<AccountId, Self>; fn slash(
asset: Self::AssetId,
who: &AccountId,
amount: Self::Balance
) -> (CreditOf<AccountId, Self>, Self::Balance); fn deposit(
asset: Self::AssetId,
who: &AccountId,
value: Self::Balance
) -> Result<DebtOf<AccountId, Self>, DispatchError>; fn withdraw(
asset: Self::AssetId,
who: &AccountId,
value: Self::Balance
) -> Result<CreditOf<AccountId, Self>, DispatchError>; fn pair(
asset: Self::AssetId,
amount: Self::Balance
) -> (DebtOf<AccountId, Self>, CreditOf<AccountId, Self>) { ... } fn resolve(
who: &AccountId,
credit: CreditOf<AccountId, Self>
) -> Result<(), CreditOf<AccountId, Self>> { ... } fn settle(
who: &AccountId,
debt: DebtOf<AccountId, Self>
) -> Result<CreditOf<AccountId, Self>, DebtOf<AccountId, Self>> { ... } }
Expand description
A fungible token class where any creation and deletion of tokens is semi-explicit and where the total supply is maintained automatically.
This is auto-implemented when a token class has Unbalanced
implemented.
Associated Types
type OnDropDebt: HandleImbalanceDrop<Self::AssetId, Self::Balance>
type OnDropDebt: HandleImbalanceDrop<Self::AssetId, Self::Balance>
The type for managing what happens when an instance of Debt
is dropped without being used.
type OnDropCredit: HandleImbalanceDrop<Self::AssetId, Self::Balance>
type OnDropCredit: HandleImbalanceDrop<Self::AssetId, Self::Balance>
The type for managing what happens when an instance of Credit
is dropped without being
used.
Required methods
Reduce the total issuance by amount
and return the according imbalance. The imbalance will
typically be used to reduce an account by the same amount with e.g. settle
.
This is infallible, but doesn’t guarantee that the entire amount
is burnt, for example
in the case of underflow.
Increase the total issuance by amount
and return the according imbalance. The imbalance
will typically be used to increase an account by the same amount with e.g.
resolve_into_existing
or resolve_creating
.
This is infallible, but doesn’t guarantee that the entire amount
is issued, for example
in the case of overflow.
Deducts up to value
from the combined balance of who
, preferring to deduct from the
free balance. This function cannot fail.
The resulting imbalance is the first item of the tuple returned.
As much funds up to value
will be deducted as possible. If this is less than value
,
then a non-zero second item will be returned.
Mints exactly value
into the asset
account of who
.
If who
doesn’t exist, nothing is done and an Err
returned. This could happen because it
the account doesn’t yet exist and it isn’t possible to create it under the current
circumstances and with value
in it.
Removes value
free asset
balance from who
account if possible.
If the removal is not possible, then it returns Err
and nothing is changed.
If the operation is successful, this will return Ok
with a NegativeImbalance
whose value
is no less than value
. It may be more in the case that removing it reduced it below
Self::minimum_balance()
.
Provided methods
Produce a pair of imbalances that cancel each other out exactly.
This is just the same as burning and issuing the same amount and has no effect on the total issuance.
The balance of who
is increased in order to counter credit
. If the whole of credit
cannot be countered, then nothing is changed and the original credit
is returned in an
Err
.
Please note: If credit.peek()
is less than Self::minimum_balance()
, then who
must
already exist for this to succeed.