referrerpolicy=no-referrer-when-downgrade

Deposit

Trait Deposit 

Source
pub trait Deposit<T: Config>: Sealed {
    const SUPPORTS_PGAS: bool;

    // Required methods
    fn init_contract(contract: &T::AccountId) -> DispatchResult;
    fn destroy_contract(contract: &T::AccountId) -> DispatchResult;
    fn charge_and_hold(
        reason: HoldReason,
        src: Funds<'_, T::AccountId>,
        to: &T::AccountId,
        amount: BalanceOf<T>,
    ) -> DispatchResult;
    fn refund_on_hold(
        reason: HoldReason,
        from: &T::AccountId,
        dst: Funds<'_, T::AccountId>,
        amount: BalanceOf<T>,
    ) -> DispatchResult;
    fn total_on_hold(reason: HoldReason, who: &T::AccountId) -> BalanceOf<T>;
    fn refund_all(
        from: &T::AccountId,
        dst: Funds<'_, T::AccountId>,
    ) -> Result<BalanceOf<T>, DispatchError>;
    fn migrate_native_to_pgas(
        reason: HoldReason,
        contract: &T::AccountId,
        amount: BalanceOf<T>,
    ) -> DispatchResult;
}
Expand description

Payment backend used to charge storage deposits.

Required Associated Constants§

Source

const SUPPORTS_PGAS: bool

Whether this backend supports PGAS.

When false, the v4 multi-block migration’s PGAS-related phases (steps 1 and 2) are no-ops, since there is no PGAS asset to migrate native deposits over to.

Required Methods§

Source

fn init_contract(contract: &T::AccountId) -> DispatchResult

Mint each backend’s existential deposit into contract.

Used by [crate::exec] when bringing a new contract account into existence.

Source

fn destroy_contract(contract: &T::AccountId) -> DispatchResult

Tear down the per-backend balance state that Self::init_contract set up.

Used by [crate::exec::Stack::do_terminate] when destroying a contract.

Source

fn charge_and_hold( reason: HoldReason, src: Funds<'_, T::AccountId>, to: &T::AccountId, amount: BalanceOf<T>, ) -> DispatchResult

Charge amount from src to to and place it on hold under reason.

§Parameters
  • reason: hold reason to place the charge under.
  • src: source of the charge. See [Funds].
  • to: account on which the hold is placed.
  • amount: amount to charge.
Source

fn refund_on_hold( reason: HoldReason, from: &T::AccountId, dst: Funds<'_, T::AccountId>, amount: BalanceOf<T>, ) -> DispatchResult

Refund amount of held funds from contract from.

§Parameters
  • reason: hold reason the funds were placed under.
  • from: contract whose hold is being released.
  • dst: destination of the refund. See [Funds]. Also the attribution key used to cap the native portion via [NativeDepositOf].
  • amount: amount to refund.
Source

fn total_on_hold(reason: HoldReason, who: &T::AccountId) -> BalanceOf<T>

Total amount held for who under reason.

§Parameters
  • reason: hold reason to query.
  • who: account whose held balance is returned.
Source

fn refund_all( from: &T::AccountId, dst: Funds<'_, T::AccountId>, ) -> Result<BalanceOf<T>, DispatchError>

Refund every storage-deposit fund held on from to dst, ignoring the per-contributor caps that govern partial refunds. Used at contract termination.

Returns the total amount released, so the storage meter can finalise its deposit accounting.

§Parameters
  • from: contract whose hold is being released.
  • dst: destination of the refund. See [Funds].
Source

fn migrate_native_to_pgas( reason: HoldReason, contract: &T::AccountId, amount: BalanceOf<T>, ) -> DispatchResult

Burn the native currency held on contract under reason and replace it with the same amount of PGAS, minted into contract and placed on hold under the same reason.

Only used by the v4 multi-block migration (see crate::migrations::v4) to move pre-existing native storage deposits over to PGAS. Not part of the regular charge/refund flow.

§Parameters
  • reason: hold reason whose balance is being migrated.
  • contract: account holding the funds to migrate.
  • amount: amount to migrate from native to PGAS.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: Config> Deposit<T> for ()

Default backend: every storage deposit charge goes through the native currency.

Source§

fn init_contract(to: &T::AccountId) -> DispatchResult

The native ED is freshly minted and immediately deactivated so that active issuance, and therefore opengov conviction, inflation accounting, etc., is undisturbed by contract creation. The contract holds a system consumer for as long as it exists, so this minted ED is not extractable: the account cannot be reaped.

Source§

const SUPPORTS_PGAS: bool = false

Source§

fn destroy_contract(contract: &T::AccountId) -> DispatchResult

Source§

fn charge_and_hold( reason: HoldReason, src: Funds<'_, T::AccountId>, to: &T::AccountId, amount: BalanceOf<T>, ) -> DispatchResult

Source§

fn refund_on_hold( reason: HoldReason, from: &T::AccountId, dst: Funds<'_, T::AccountId>, amount: BalanceOf<T>, ) -> DispatchResult

Source§

fn total_on_hold(reason: HoldReason, who: &T::AccountId) -> BalanceOf<T>

Source§

fn refund_all( from: &T::AccountId, dst: Funds<'_, T::AccountId>, ) -> Result<BalanceOf<T>, DispatchError>

Source§

fn migrate_native_to_pgas( _reason: HoldReason, _contract: &T::AccountId, _amount: BalanceOf<T>, ) -> DispatchResult

Implementors§

Source§

impl<T, Mutator, Holder, Freezer, Id, RefundPercent> Deposit<T> for PGasDeposit<T, Mutator, Holder, Freezer, Id, RefundPercent>
where T: Config, Mutator: Mutate<T::AccountId, Balance = BalanceOf<T>>, Holder: MutateHold<T::AccountId, Balance = BalanceOf<T>, AssetId = <Mutator as Inspect<T::AccountId>>::AssetId>, <Holder as InspectHold<T::AccountId>>::Reason: From<HoldReason>, Freezer: Mutate<T::AccountId, Balance = BalanceOf<T>, AssetId = <Mutator as Inspect<T::AccountId>>::AssetId>, <Freezer as Inspect<T::AccountId>>::Id: From<FreezeReason>, Id: Get<<Mutator as Inspect<T::AccountId>>::AssetId>, RefundPercent: Get<Perbill>,