referrerpolicy=no-referrer-when-downgrade

Trait polkadot_sdk_frame::traits::ReservableCurrency

pub trait ReservableCurrency<AccountId>: Currency<AccountId> {
    // Required methods
    fn can_reserve(who: &AccountId, value: Self::Balance) -> bool;
    fn slash_reserved(
        who: &AccountId,
        value: Self::Balance,
    ) -> (Self::NegativeImbalance, Self::Balance);
    fn reserved_balance(who: &AccountId) -> Self::Balance;
    fn reserve(
        who: &AccountId,
        value: Self::Balance,
    ) -> Result<(), DispatchError>;
    fn unreserve(who: &AccountId, value: Self::Balance) -> Self::Balance;
    fn repatriate_reserved(
        slashed: &AccountId,
        beneficiary: &AccountId,
        value: Self::Balance,
        status: BalanceStatus,
    ) -> Result<Self::Balance, DispatchError>;
}
Expand description

A currency where funds can be reserved from the user.

Required Methods§

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

Same result as reserve(who, value) (but without the side-effects) assuming there are no balance changes in the meantime.

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

Deducts up to value from reserved balance of who. This function cannot fail.

As much funds up to value will be deducted as possible. If the reserve balance of who is less than value, then the second item will be equal to the value not able to be slashed.

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

The amount of the balance of a given account that is externally reserved; this can still get slashed, but gets slashed last of all.

This balance is a ‘reserve’ balance that other subsystems use in order to set aside tokens that are still ‘owned’ by the account holder, but which are suspendable.

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

fn reserve(who: &AccountId, value: Self::Balance) -> Result<(), DispatchError>

Moves value from balance to reserved balance.

If the free balance is lower than value, then no funds will be moved and an Err will be returned to notify of this. This is different behavior than unreserve.

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

Moves up to value from reserved balance to free balance. This function cannot fail.

As much funds up to value will be moved as possible. If the reserve balance of who is less than value, then the remaining amount will be returned. This is different behavior than reserve.

fn repatriate_reserved( slashed: &AccountId, beneficiary: &AccountId, value: Self::Balance, status: BalanceStatus, ) -> Result<Self::Balance, DispatchError>

Moves up to value from reserved balance of account slashed to balance of account beneficiary. beneficiary must exist for this to succeed. If it does not, Err will be returned. Funds will be placed in either the free balance or the reserved balance, depending on the status.

As much funds up to value will be deducted as possible. If this is less than value, then Ok(non_zero) will be returned.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl<AccountId> ReservableCurrency<AccountId> for ()

§

fn can_reserve(_: &AccountId, _: <() as Currency<AccountId>>::Balance) -> bool

§

fn slash_reserved( _: &AccountId, _: <() as Currency<AccountId>>::Balance, ) -> (<() as Currency<AccountId>>::NegativeImbalance, <() as Currency<AccountId>>::Balance)

§

fn reserved_balance(_: &AccountId) -> <() as Currency<AccountId>>::Balance

§

fn reserve( _: &AccountId, _: <() as Currency<AccountId>>::Balance, ) -> Result<(), DispatchError>

§

fn unreserve( _: &AccountId, _: <() as Currency<AccountId>>::Balance, ) -> <() as Currency<AccountId>>::Balance

§

fn repatriate_reserved( _: &AccountId, _: &AccountId, _: <() as Currency<AccountId>>::Balance, _: BalanceStatus, ) -> Result<<() as Currency<AccountId>>::Balance, DispatchError>

Implementors§