Trait subsocial_runtime::Currency [−][src]
Abstraction over a fungible assets system.
Associated Types
type Balance: Default + Copy + Debug + FullCodec + MaybeSerializeDeserialize + AtLeast32BitUnsigned[src]
The balance of an account.
type PositiveImbalance: Imbalance<Self::Balance>[src]
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>[src]
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.
Required methods
pub fn total_balance(who: &AccountId) -> Self::Balance[src]
The combined balance of who.
pub fn can_slash(who: &AccountId, value: Self::Balance) -> bool[src]
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.
pub fn total_issuance() -> Self::Balance[src]
The total amount of issuance in the system.
pub fn minimum_balance() -> Self::Balance[src]
The minimum balance any single account may have. This is equivalent to the Balances module’s
ExistentialDeposit.
pub fn burn(amount: Self::Balance) -> Self::PositiveImbalance[src]
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.
pub fn issue(amount: Self::Balance) -> Self::NegativeImbalance[src]
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.
pub fn free_balance(who: &AccountId) -> Self::Balance[src]
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.
system::AccountNonce is also deleted if ReservedBalance is also zero (it also gets
collapsed to zero if it ever becomes less than ExistentialDeposit.
pub fn ensure_can_withdraw(
who: &AccountId,
_amount: Self::Balance,
reasons: WithdrawReasons,
new_balance: Self::Balance
) -> Result<(), DispatchError>[src]
who: &AccountId,
_amount: Self::Balance,
reasons: WithdrawReasons,
new_balance: Self::Balance
) -> Result<(), DispatchError>
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.
pub fn transfer(
source: &AccountId,
dest: &AccountId,
value: Self::Balance,
existence_requirement: ExistenceRequirement
) -> Result<(), DispatchError>[src]
source: &AccountId,
dest: &AccountId,
value: Self::Balance,
existence_requirement: ExistenceRequirement
) -> Result<(), DispatchError>
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.
pub fn slash(
who: &AccountId,
value: Self::Balance
) -> (Self::NegativeImbalance, Self::Balance)[src]
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.
pub fn deposit_into_existing(
who: &AccountId,
value: Self::Balance
) -> Result<Self::PositiveImbalance, DispatchError>[src]
who: &AccountId,
value: Self::Balance
) -> Result<Self::PositiveImbalance, DispatchError>
Mints value to the free balance of who.
If who doesn’t exist, nothing is done and an Err returned.
pub fn deposit_creating(
who: &AccountId,
value: Self::Balance
) -> Self::PositiveImbalance[src]
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.
pub fn withdraw(
who: &AccountId,
value: Self::Balance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement
) -> Result<Self::NegativeImbalance, DispatchError>[src]
who: &AccountId,
value: Self::Balance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement
) -> Result<Self::NegativeImbalance, DispatchError>
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.
If the operation is successful, this will return Ok with a NegativeImbalance whose value
is value.
pub fn make_free_balance_be(
who: &AccountId,
balance: Self::Balance
) -> SignedImbalance<Self::Balance, Self::PositiveImbalance>[src]
who: &AccountId,
balance: Self::Balance
) -> SignedImbalance<Self::Balance, Self::PositiveImbalance>
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.
Provided methods
pub fn pair(
amount: Self::Balance
) -> (Self::PositiveImbalance, Self::NegativeImbalance)[src]
amount: Self::Balance
) -> (Self::PositiveImbalance, Self::NegativeImbalance)
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.
pub fn resolve_into_existing(
who: &AccountId,
value: Self::NegativeImbalance
) -> Result<(), Self::NegativeImbalance>[src]
who: &AccountId,
value: Self::NegativeImbalance
) -> Result<(), Self::NegativeImbalance>
Similar to deposit_creating, only accepts a NegativeImbalance and returns nothing on
success.
pub fn resolve_creating(who: &AccountId, value: Self::NegativeImbalance)[src]
Similar to deposit_creating, only accepts a NegativeImbalance and returns nothing on
success.
pub fn settle(
who: &AccountId,
value: Self::PositiveImbalance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement
) -> Result<(), Self::PositiveImbalance>[src]
who: &AccountId,
value: Self::PositiveImbalance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement
) -> Result<(), Self::PositiveImbalance>
Similar to withdraw, only accepts a PositiveImbalance and returns nothing on success.
Implementations on Foreign Types
impl<T, I> Currency<<T as Trait>::AccountId> for Module<T, I> where
T: Trait<I>,
I: Instance,
<T as Trait<I>>::Balance: MaybeSerializeDeserialize,
<T as Trait<I>>::Balance: Debug, [src]
T: Trait<I>,
I: Instance,
<T as Trait<I>>::Balance: MaybeSerializeDeserialize,
<T as Trait<I>>::Balance: Debug,
type Balance = <T as Trait<I>>::Balance
type PositiveImbalance = PositiveImbalance<T, I>
type NegativeImbalance = NegativeImbalance<T, I>
pub fn total_balance(
who: &<T as Trait>::AccountId
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance[src]
who: &<T as Trait>::AccountId
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
pub fn can_slash(
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> bool[src]
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> bool
pub fn total_issuance(
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance[src]
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
pub fn minimum_balance(
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance[src]
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
pub fn burn(
amount: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::PositiveImbalance[src]
amount: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::PositiveImbalance
pub fn issue(
amount: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::NegativeImbalance[src]
amount: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::NegativeImbalance
pub fn free_balance(
who: &<T as Trait>::AccountId
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance[src]
who: &<T as Trait>::AccountId
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
pub fn ensure_can_withdraw(
who: &<T as Trait>::AccountId,
amount: <T as Trait<I>>::Balance,
reasons: WithdrawReasons,
new_balance: <T as Trait<I>>::Balance
) -> Result<(), DispatchError>[src]
who: &<T as Trait>::AccountId,
amount: <T as Trait<I>>::Balance,
reasons: WithdrawReasons,
new_balance: <T as Trait<I>>::Balance
) -> Result<(), DispatchError>
pub fn transfer(
transactor: &<T as Trait>::AccountId,
dest: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance,
existence_requirement: ExistenceRequirement
) -> Result<(), DispatchError>[src]
transactor: &<T as Trait>::AccountId,
dest: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance,
existence_requirement: ExistenceRequirement
) -> Result<(), DispatchError>
pub fn slash(
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> (<Module<T, I> as Currency<<T as Trait>::AccountId>>::NegativeImbalance, <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance)[src]
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> (<Module<T, I> as Currency<<T as Trait>::AccountId>>::NegativeImbalance, <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance)
Slash a target account who, returning the negative imbalance created and any left over
amount that could not be slashed.
Is a no-op if value to be slashed is zero.
NOTE: slash() prefers free balance, but assumes that reserve balance can be drawn
from in extreme circumstances. can_slash() should be used prior to slash() to avoid having
to draw from reserved funds, however we err on the side of punishment if things are inconsistent
or can_slash wasn’t used appropriately.
pub fn deposit_into_existing(
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> Result<<Module<T, I> as Currency<<T as Trait>::AccountId>>::PositiveImbalance, DispatchError>[src]
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> Result<<Module<T, I> as Currency<<T as Trait>::AccountId>>::PositiveImbalance, DispatchError>
Deposit some value into the free balance of an existing target account who.
Is a no-op if the value to be deposited is zero.
pub fn deposit_creating(
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::PositiveImbalance[src]
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> <Module<T, I> as Currency<<T as Trait>::AccountId>>::PositiveImbalance
Deposit some value into the free balance of who, possibly creating a new account.
This function is a no-op if:
- the
valueto be deposited is zero; or - if the
valueto be deposited is less than the ED and the account does not yet exist; or valueis so large it would cause the balance ofwhoto overflow.
pub fn withdraw(
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement
) -> Result<<Module<T, I> as Currency<<T as Trait>::AccountId>>::NegativeImbalance, DispatchError>[src]
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance,
reasons: WithdrawReasons,
liveness: ExistenceRequirement
) -> Result<<Module<T, I> as Currency<<T as Trait>::AccountId>>::NegativeImbalance, DispatchError>
Withdraw some free balance from an account, respecting existence requirements.
Is a no-op if value to be withdrawn is zero.
pub fn make_free_balance_be(
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> SignedImbalance<<Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance, <Module<T, I> as Currency<<T as Trait>::AccountId>>::PositiveImbalance>[src]
who: &<T as Trait>::AccountId,
value: <Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance
) -> SignedImbalance<<Module<T, I> as Currency<<T as Trait>::AccountId>>::Balance, <Module<T, I> as Currency<<T as Trait>::AccountId>>::PositiveImbalance>
Force the new free balance of a target account who to some new value balance.