referrerpolicy=no-referrer-when-downgrade

Trait polkadot_sdk_frame::traits::tokens::fungible::hold::Unbalanced

pub trait Unbalanced<AccountId>: Inspect<AccountId> {
    // Required method
    fn set_balance_on_hold(
        reason: &Self::Reason,
        who: &AccountId,
        amount: Self::Balance,
    ) -> Result<(), DispatchError>;

    // Provided methods
    fn decrease_balance_on_hold(
        reason: &Self::Reason,
        who: &AccountId,
        amount: Self::Balance,
        precision: Precision,
    ) -> Result<Self::Balance, DispatchError> { ... }
    fn increase_balance_on_hold(
        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§

fn set_balance_on_hold( reason: &Self::Reason, who: &AccountId, amount: Self::Balance, ) -> Result<(), DispatchError>

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§

fn decrease_balance_on_hold( 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 Exact and it cannot be reduced by that amount for some reason, return Err and don’t reduce it at all. If precision is 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.

fn increase_balance_on_hold( 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§

§

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