pub trait Balanced<AccountId>: Inspect<AccountId> + Unbalanced<AccountId> {
    type OnDropDebt: HandleImbalanceDrop<Self::Balance>;
    type OnDropCredit: HandleImbalanceDrop<Self::Balance>;

    // Provided methods
    fn rescind(amount: Self::Balance) -> Debt<AccountId, Self> { ... }
    fn issue(amount: Self::Balance) -> Credit<AccountId, Self> { ... }
    fn pair(
        amount: Self::Balance
    ) -> (Debt<AccountId, Self>, Credit<AccountId, Self>) { ... }
    fn deposit(
        who: &AccountId,
        value: Self::Balance,
        precision: Precision
    ) -> Result<Debt<AccountId, Self>, DispatchError> { ... }
    fn withdraw(
        who: &AccountId,
        value: Self::Balance,
        precision: Precision,
        preservation: Preservation,
        force: Fortitude
    ) -> Result<Credit<AccountId, Self>, DispatchError> { ... }
    fn resolve(
        who: &AccountId,
        credit: Credit<AccountId, Self>
    ) -> Result<(), Credit<AccountId, Self>> { ... }
    fn settle(
        who: &AccountId,
        debt: Debt<AccountId, Self>,
        preservation: Preservation
    ) -> Result<Credit<AccountId, Self>, Debt<AccountId, Self>> { ... }
    fn done_rescind(_amount: Self::Balance) { ... }
    fn done_issue(_amount: Self::Balance) { ... }
    fn done_deposit(_who: &AccountId, _amount: Self::Balance) { ... }
    fn done_withdraw(_who: &AccountId, _amount: Self::Balance) { ... }
}
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.

Required Associated Types§

source

type OnDropDebt: HandleImbalanceDrop<Self::Balance>

The type for managing what happens when an instance of Debt is dropped without being used.

source

type OnDropCredit: HandleImbalanceDrop<Self::Balance>

The type for managing what happens when an instance of Credit is dropped without being used.

Provided Methods§

source

fn rescind(amount: Self::Balance) -> Debt<AccountId, Self>

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.

source

fn issue(amount: Self::Balance) -> Credit<AccountId, Self>

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.

source

fn pair( amount: Self::Balance ) -> (Debt<AccountId, Self>, Credit<AccountId, Self>)

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.

source

fn deposit( who: &AccountId, value: Self::Balance, precision: Precision ) -> Result<Debt<AccountId, Self>, DispatchError>

Mints value into the account of who, creating it as needed.

If precision is BestEffort and value in full could not be minted (e.g. due to overflow), then the maximum is minted, up to value. If precision is Exact, then exactly value must be minted into the account of who or the operation will fail with an Err and nothing will change.

If the operation is successful, this will return Ok with a Debt of the total value added to the account.

source

fn withdraw( who: &AccountId, value: Self::Balance, precision: Precision, preservation: Preservation, force: Fortitude ) -> Result<Credit<AccountId, Self>, DispatchError>

Removes value balance from who account if possible.

If precision is BestEffort and value in full could not be removed (e.g. due to underflow), then the maximum is removed, up to value. If precision is Exact, then exactly value must be removed from the account of who or the operation will fail with an Err and nothing will change.

If the removal is needed but not possible, then it returns Err and nothing is changed. If the account needed to be deleted, then slightly more than value may be removed from the account owning since up to (but not including) minimum balance may also need to be removed.

If the operation is successful, this will return Ok with a Credit of the total value removed from the account.

source

fn resolve( who: &AccountId, credit: Credit<AccountId, Self> ) -> Result<(), Credit<AccountId, Self>>

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.

source

fn settle( who: &AccountId, debt: Debt<AccountId, Self>, preservation: Preservation ) -> Result<Credit<AccountId, Self>, Debt<AccountId, Self>>

The balance of who is decreased in order to counter debt. If the whole of debt cannot be countered, then nothing is changed and the original debt is returned in an Err.

source

fn done_rescind(_amount: Self::Balance)

source

fn done_issue(_amount: Self::Balance)

source

fn done_deposit(_who: &AccountId, _amount: Self::Balance)

source

fn done_withdraw(_who: &AccountId, _amount: Self::Balance)

Implementors§

source§

impl<F: Inspect<AccountId> + Unbalanced<AccountId> + Balanced<AccountId>, A: Get<<F as Inspect<AccountId>>::AssetId>, AccountId> Balanced<AccountId> for ItemOf<F, A, AccountId>

§

type OnDropDebt = ConvertImbalanceDropHandler<AccountId, <ItemOf<F, A, AccountId> as Inspect<AccountId>>::Balance, <F as Inspect<AccountId>>::AssetId, A, <F as Balanced<AccountId>>::OnDropDebt>

§

type OnDropCredit = ConvertImbalanceDropHandler<AccountId, <ItemOf<F, A, AccountId> as Inspect<AccountId>>::Balance, <F as Inspect<AccountId>>::AssetId, A, <F as Balanced<AccountId>>::OnDropCredit>