Module pallet_contracts::chain_extension[][src]

Expand description

A mechanism for runtime authors to augment the functionality of contracts.

The runtime is able to call into any contract and retrieve the result using bare_call. This already allows customization of runtime behaviour by user generated code (contracts). However, often it is more straightforward to allow the reverse behaviour: The contract calls into the runtime. We call the latter one a “chain extension” because it allows the chain to extend the set of functions that are callable by a contract.

In order to create a chain extension the runtime author implements the ChainExtension trait and declares it in this pallet’s configuration Trait. All types required for this endeavour are defined or re-exported in this module. There is an implementation on () which can be used to signal that no chain extension is available.

Security

The chain author alone is responsible for the security of the chain extension. This includes avoiding the exposure of exploitable functions and charging the appropriate amount of weight. In order to do so benchmarks must be written and the charge_weight function must be called before carrying out any action that causes the consumption of the chargeable weight. It cannot be overstated how delicate of a process the creation of a chain extension is. Check whether using bare_call suffices for the use case at hand.

Benchmarking

The builtin contract callable functions that pallet-contracts provides all have benchmarks that determine the correct weight that an invocation of these functions induces. In order to be able to charge the correct weight for the functions defined by a chain extension benchmarks must be written, too. In the near future this crate will provide the means for easier creation of those specialized benchmarks.

Example

The ink! repository maintains an end-to-end example on how to use a chain extension in order to provide new features to ink! contracts.

Re-exports

pub use crate::Config;

Structs

Grants the chain extension access to its parameters and execution environment.

Flags used by a contract to customize exit behaviour.

Enums

The initial state of an Environment. See typestate programming.

Determines the exit behaviour and return value of a chain extension.

Traits

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

An interface that provides access to the external environment in which the smart-contract is executed.

System configuration trait. Implemented by runtime.

Similar to From, except that the onus is on the part of the caller to ensure that data passed in makes sense. Basically, you’re not guaranteed to get anything sensible out.

Type Definitions

Result that returns a DispatchError on error.