Trait pallet_revive::chain_extension::ChainExtension
source · pub trait ChainExtension<C: Config> {
// Required method
fn call<E: Ext<T = C>, M: ?Sized + Memory<E::T>>(
&mut self,
env: Environment<'_, '_, E, M>,
) -> 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§
sourcefn call<E: Ext<T = C>, M: ?Sized + Memory<E::T>>(
&mut self,
env: Environment<'_, '_, E, M>,
) -> Result<RetVal>
fn call<E: Ext<T = C>, M: ?Sized + Memory<E::T>>( &mut self, env: Environment<'_, '_, E, M>, ) -> 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§
sourcefn enabled() -> bool
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
.