[][src]Trait srml_support::traits::Currency

pub trait Currency<AccountId> {
    type Balance: SimpleArithmetic + As<usize> + As<u64> + Codec + Copy + MaybeSerializeDebug + Default;
    type PositiveImbalance: Imbalance<Self::Balance, Opposite = Self::NegativeImbalance>;
    type NegativeImbalance: Imbalance<Self::Balance, Opposite = Self::PositiveImbalance>;
    fn total_balance(who: &AccountId) -> Self::Balance;
fn can_slash(who: &AccountId, value: Self::Balance) -> bool;
fn total_issuance() -> Self::Balance;
fn minimum_balance() -> Self::Balance;
fn free_balance(who: &AccountId) -> Self::Balance;
fn ensure_can_withdraw(
        who: &AccountId,
        _amount: Self::Balance,
        reason: WithdrawReason,
        new_balance: Self::Balance
    ) -> Result<(), &'static str>;
fn transfer(
        source: &AccountId,
        dest: &AccountId,
        value: Self::Balance
    ) -> Result<(), &'static str>;
fn slash(
        who: &AccountId,
        value: Self::Balance
    ) -> (Self::NegativeImbalance, Self::Balance);
fn deposit_into_existing(
        who: &AccountId,
        value: Self::Balance
    ) -> Result<Self::PositiveImbalance, &'static str>;
fn withdraw(
        who: &AccountId,
        value: Self::Balance,
        reason: WithdrawReason,
        liveness: ExistenceRequirement
    ) -> Result<Self::NegativeImbalance, &'static str>;
fn deposit_creating(
        who: &AccountId,
        value: Self::Balance
    ) -> Self::PositiveImbalance;
fn make_free_balance_be(
        who: &AccountId,
        balance: Self::Balance
    ) -> (SignedImbalance<Self::Balance, Self::PositiveImbalance>, UpdateBalanceOutcome); }

Abstraction over a fungible assets system.

Associated Types

type Balance: SimpleArithmetic + As<usize> + As<u64> + Codec + Copy + MaybeSerializeDebug + Default

The balance of an account.

type PositiveImbalance: Imbalance<Self::Balance, Opposite = Self::NegativeImbalance>

The opaque token type for an imbalance. This is returned by unbalanced operations and must be dealt with. It may be dropped but cannot be cloned.

type NegativeImbalance: Imbalance<Self::Balance, Opposite = Self::PositiveImbalance>

The opaque token type for an imbalance. This is returned by unbalanced operations and must be dealt with. It may be dropped but cannot be cloned.

Loading content...

Required methods

fn total_balance(who: &AccountId) -> Self::Balance

The combined balance of who.

fn can_slash(who: &AccountId, value: Self::Balance) -> bool

Same result as slash(who, value) (but without the side-effects) assuming there are no balance changes in the meantime and only the reserved balance is not taken into account.

fn total_issuance() -> Self::Balance

The total amount of issuance in the system.

fn minimum_balance() -> Self::Balance

The minimum balance any single account may have. This is equivalent to the Balances module's ExistentialDeposit.

fn free_balance(who: &AccountId) -> Self::Balance

The 'free' balance of a given account.

This is the only balance that matters in terms of most operations on tokens. It alone is used to determine the balance when in the contract execution environment. When this balance falls below the value of ExistentialDeposit, then the 'current account' is deleted: specifically FreeBalance. Further, the OnFreeBalanceZero callback is invoked, giving a chance to external modules to clean up data associated with the deleted account.

system::AccountNonce is also deleted if ReservedBalance is also zero (it also gets collapsed to zero if it ever becomes less than ExistentialDeposit.

fn ensure_can_withdraw(
    who: &AccountId,
    _amount: Self::Balance,
    reason: WithdrawReason,
    new_balance: Self::Balance
) -> Result<(), &'static str>

Returns Ok iff the account is able to make a withdrawal of the given amount for the given reason. Basically, it's just a dry-run of withdraw.

Err(...) with the reason why not otherwise.

fn transfer(
    source: &AccountId,
    dest: &AccountId,
    value: Self::Balance
) -> Result<(), &'static str>

Transfer some liquid free balance to another staker.

This is a very high-level function. It will ensure all appropriate fees are paid and no imbalance in the system remains.

fn slash(
    who: &AccountId,
    value: Self::Balance
) -> (Self::NegativeImbalance, Self::Balance)

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.

fn deposit_into_existing(
    who: &AccountId,
    value: Self::Balance
) -> Result<Self::PositiveImbalance, &'static str>

Mints value to the free balance of who.

If who doesn't exist, nothing is done and an Err returned.

fn withdraw(
    who: &AccountId,
    value: Self::Balance,
    reason: WithdrawReason,
    liveness: ExistenceRequirement
) -> Result<Self::NegativeImbalance, &'static str>

Removes some free balance from who account for reason if possible. If liveness is KeepAlive, then no less than ExistentialDeposit must be left remaining.

This checks any locks, vesting, and liquidity requirements. If the removal is not possible, then it returns Err.

fn deposit_creating(
    who: &AccountId,
    value: Self::Balance
) -> Self::PositiveImbalance

Adds up to value to the free balance of who. If who doesn't exist, it is created.

Infallible.

fn make_free_balance_be(
    who: &AccountId,
    balance: Self::Balance
) -> (SignedImbalance<Self::Balance, Self::PositiveImbalance>, UpdateBalanceOutcome)

Ensure an account's free balance equals some value; this will create the account if needed.

Returns a signed imbalance and status to indicate if the account was successfully updated or update has led to killing of the account.

Loading content...

Implementors

Loading content...