pallet_contracts::chain_extension

Trait ChainExtension

source
pub trait ChainExtension<C: Config> {
    // Required method
    fn call<E: Ext<T = C>>(
        &mut self,
        env: Environment<'_, '_, E, InitState>,
    ) -> Result<RetVal>;

    // Provided method
    fn enabled() -> bool { ... }
}
Expand description

A trait used to extend the set of contract callable functions.

In order to create a custom chain extension this trait must be implemented and supplied to the pallet contracts configuration trait as the associated type of the same name. Consult the module documentation for a general explanation of chain extensions.

§Lifetime

The extension will be Default initialized at the beginning of each call (not per call stack) and dropped afterwards. Hence any value held inside the extension can be used as a per-call scratch buffer.

Required Methods§

source

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

Call the chain extension logic.

This is the only function that needs to be implemented in order to write a chain extensions. It is called whenever a contract calls the seal_call_chain_extension imported wasm function.

§Parameters
  • env: Access to the remaining arguments and the execution environment.
§Return

In case of Err the contract execution is immediately suspended and the passed error is returned to the caller. Otherwise the value of RetVal determines the exit behaviour.

§Note

The Self::call can be invoked within a read-only context, where any state-changing calls are disallowed. This information can be obtained using env.ext().is_read_only(). It is crucial for the implementer to handle this scenario appropriately.

Provided Methods§

source

fn enabled() -> bool

Determines whether chain extensions are enabled for this chain.

The default implementation returns true. Therefore it is not necessary to overwrite this function when implementing a chain extension. In case of false the deployment of a contract that references seal_call_chain_extension will be denied and calling this function will return NoChainExtension without first calling into call.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<C: Config> ChainExtension<C> for ()

source§

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

source§

fn enabled() -> bool

source§

impl<C: Config, TupleElement0: RegisteredChainExtension<C>> ChainExtension<C> for (TupleElement0,)

source§

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

source§

fn enabled() -> bool

source§

impl<C: Config, TupleElement0: RegisteredChainExtension<C>, TupleElement1: RegisteredChainExtension<C>> ChainExtension<C> for (TupleElement0, TupleElement1)

source§

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

source§

fn enabled() -> bool

source§

impl<C: Config, TupleElement0: RegisteredChainExtension<C>, TupleElement1: RegisteredChainExtension<C>, TupleElement2: RegisteredChainExtension<C>> ChainExtension<C> for (TupleElement0, TupleElement1, TupleElement2)

source§

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

source§

fn enabled() -> bool

source§

impl<C: Config, TupleElement0: RegisteredChainExtension<C>, TupleElement1: RegisteredChainExtension<C>, TupleElement2: RegisteredChainExtension<C>, TupleElement3: RegisteredChainExtension<C>> ChainExtension<C> for (TupleElement0, TupleElement1, TupleElement2, TupleElement3)

source§

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

source§

fn enabled() -> bool

source§

impl<C: Config, TupleElement0: RegisteredChainExtension<C>, TupleElement1: RegisteredChainExtension<C>, TupleElement2: RegisteredChainExtension<C>, TupleElement3: RegisteredChainExtension<C>, TupleElement4: RegisteredChainExtension<C>> ChainExtension<C> for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4)

source§

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

source§

fn enabled() -> bool

source§

impl<C: Config, TupleElement0: RegisteredChainExtension<C>, TupleElement1: RegisteredChainExtension<C>, TupleElement2: RegisteredChainExtension<C>, TupleElement3: RegisteredChainExtension<C>, TupleElement4: RegisteredChainExtension<C>, TupleElement5: RegisteredChainExtension<C>> ChainExtension<C> for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5)

source§

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

source§

fn enabled() -> bool

source§

impl<C: Config, TupleElement0: RegisteredChainExtension<C>, TupleElement1: RegisteredChainExtension<C>, TupleElement2: RegisteredChainExtension<C>, TupleElement3: RegisteredChainExtension<C>, TupleElement4: RegisteredChainExtension<C>, TupleElement5: RegisteredChainExtension<C>, TupleElement6: RegisteredChainExtension<C>> ChainExtension<C> for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6)

source§

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

source§

fn enabled() -> bool

source§

impl<C: Config, TupleElement0: RegisteredChainExtension<C>, TupleElement1: RegisteredChainExtension<C>, TupleElement2: RegisteredChainExtension<C>, TupleElement3: RegisteredChainExtension<C>, TupleElement4: RegisteredChainExtension<C>, TupleElement5: RegisteredChainExtension<C>, TupleElement6: RegisteredChainExtension<C>, TupleElement7: RegisteredChainExtension<C>> ChainExtension<C> for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7)

source§

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

source§

fn enabled() -> bool

source§

impl<C: Config, TupleElement0: RegisteredChainExtension<C>, TupleElement1: RegisteredChainExtension<C>, TupleElement2: RegisteredChainExtension<C>, TupleElement3: RegisteredChainExtension<C>, TupleElement4: RegisteredChainExtension<C>, TupleElement5: RegisteredChainExtension<C>, TupleElement6: RegisteredChainExtension<C>, TupleElement7: RegisteredChainExtension<C>, TupleElement8: RegisteredChainExtension<C>> ChainExtension<C> for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7, TupleElement8)

source§

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

source§

fn enabled() -> bool

source§

impl<C: Config, TupleElement0: RegisteredChainExtension<C>, TupleElement1: RegisteredChainExtension<C>, TupleElement2: RegisteredChainExtension<C>, TupleElement3: RegisteredChainExtension<C>, TupleElement4: RegisteredChainExtension<C>, TupleElement5: RegisteredChainExtension<C>, TupleElement6: RegisteredChainExtension<C>, TupleElement7: RegisteredChainExtension<C>, TupleElement8: RegisteredChainExtension<C>, TupleElement9: RegisteredChainExtension<C>> ChainExtension<C> for (TupleElement0, TupleElement1, TupleElement2, TupleElement3, TupleElement4, TupleElement5, TupleElement6, TupleElement7, TupleElement8, TupleElement9)

source§

fn call<E: Ext<T = C>>( &mut self, env: Environment<'_, '_, E, InitState>, ) -> Result<RetVal>

source§

fn enabled() -> bool

Implementors§