Trait frame_support::traits::tokens::fungibles::hold::Unbalanced

source ·
pub trait Unbalanced<AccountId>: Inspect<AccountId> {
    // Required method
    fn set_balance_on_hold(
        asset: Self::AssetId,
        reason: &Self::Reason,
        who: &AccountId,
        amount: Self::Balance,
    ) -> DispatchResult;

    // Provided methods
    fn decrease_balance_on_hold(
        asset: Self::AssetId,
        reason: &Self::Reason,
        who: &AccountId,
        amount: Self::Balance,
        precision: Precision,
    ) -> Result<Self::Balance, DispatchError> { ... }
    fn increase_balance_on_hold(
        asset: Self::AssetId,
        reason: &Self::Reason,
        who: &AccountId,
        amount: Self::Balance,
        precision: Precision,
    ) -> Result<Self::Balance, DispatchError> { ... }
}
Expand description

A fungible, holdable token class where the balance on hold can be set arbitrarily.

WARNING Do not use this directly unless you want trouble, since it allows you to alter account balances without keeping the issuance up to date. It has no safeguards against accidentally creating token imbalances in your system leading to accidental inflation or deflation. It’s really just for the underlying datatype to implement so the user gets the much safer Balanced trait to use.

Required Methods§

source

fn set_balance_on_hold( asset: Self::AssetId, reason: &Self::Reason, who: &AccountId, amount: Self::Balance, ) -> DispatchResult

Forcefully set the balance on hold of who to amount. This is independent of any other balances on hold or the main (“free”) balance.

If this call executes successfully, you can assert_eq!(Self::balance_on_hold(), amount);.

This function does its best to force the balance change through, but will not break system invariants such as any Existential Deposits needed or overflows/underflows. If this cannot be done for some reason (e.g. because the account doesn’t exist) then an Err is returned.

Provided Methods§

source

fn decrease_balance_on_hold( asset: Self::AssetId, reason: &Self::Reason, who: &AccountId, amount: Self::Balance, precision: Precision, ) -> Result<Self::Balance, DispatchError>

Reduce the balance on hold of who by amount.

If precision is Precision::Exact and it cannot be reduced by that amount for some reason, return Err and don’t reduce it at all. If precision is Precision::BestEffort, then reduce the balance of who by the most that is possible, up to amount.

In either case, if Ok is returned then the inner is the amount by which is was reduced.

source

fn increase_balance_on_hold( asset: Self::AssetId, reason: &Self::Reason, who: &AccountId, amount: Self::Balance, precision: Precision, ) -> Result<Self::Balance, DispatchError>

Increase the balance on hold of who by amount.

If it cannot be increased by that amount for some reason, return Err and don’t increase it at all. If Ok, return the imbalance.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<Left: UnbalancedHold<AccountId>, Right: UnbalancedHold<AccountId, Balance = Left::Balance, Reason = Left::Reason>, Criterion: Convert<AssetKind, Either<(), Right::AssetId>>, AssetKind: AssetId, AccountId> Unbalanced<AccountId> for frame_support::traits::tokens::fungible::UnionOf<Left, Right, Criterion, AssetKind, AccountId>

source§

impl<Left: UnbalancedHold<AccountId>, Right: UnbalancedHold<AccountId, Balance = Left::Balance, Reason = Left::Reason>, Criterion: Convert<AssetKind, Either<Left::AssetId, Right::AssetId>>, AssetKind: AssetId, AccountId> Unbalanced<AccountId> for frame_support::traits::tokens::fungibles::UnionOf<Left, Right, Criterion, AssetKind, AccountId>