Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions frame/contracts/src/chain_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use sp_std::{
pub use frame_system::Config as SysConfig;
pub use pallet_contracts_primitives::ReturnFlags;
pub use sp_core::crypto::UncheckedFrom;
pub use crate::exec::Ext;
pub use crate::{Config, exec::Ext};
pub use state::Init as InitState;

/// Result that returns a [`DispatchError`] on error.
Expand All @@ -74,7 +74,7 @@ pub type Result<T> = sp_std::result::Result<T, DispatchError>;
/// 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](self) for a general explanation of chain extensions.
pub trait ChainExtension {
pub trait ChainExtension<C: Config> {
/// Call the chain extension logic.
///
/// This is the only function that needs to be implemented in order to write a
Expand All @@ -91,8 +91,9 @@ pub trait ChainExtension {
/// In case of `Err` the contract execution is immediatly suspended and the passed error
/// is returned to the caller. Otherwise the value of [`RetVal`] determines the exit
/// behaviour.
fn call<E: Ext>(func_id: u32, env: Environment<E, InitState>) -> Result<RetVal>
fn call<E>(func_id: u32, env: Environment<E, InitState>) -> Result<RetVal>
where
E: Ext<T = C>,
<E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>;

/// Determines whether chain extensions are enabled for this chain.
Expand All @@ -108,9 +109,10 @@ pub trait ChainExtension {
}

/// Implementation that indicates that no chain extension is available.
impl ChainExtension for () {
fn call<E: Ext>(_func_id: u32, mut _env: Environment<E, InitState>) -> Result<RetVal>
impl<C: Config> ChainExtension<C> for () {
fn call<E>(_func_id: u32, mut _env: Environment<E, InitState>) -> Result<RetVal>
where
E: Ext<T = C>,
<E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,
{
// Never called since [`Self::enabled()`] is set to `false`. Because we want to
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ pub trait Config: frame_system::Config {
type WeightInfo: WeightInfo;

/// Type that allows the runtime authors to add new host functions for a contract to call.
type ChainExtension: chain_extension::ChainExtension;
type ChainExtension: chain_extension::ChainExtension<Self>;

/// The maximum number of tries that can be queued for deletion.
type DeletionQueueDepth: Get<u32>;
Expand Down
5 changes: 3 additions & 2 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ impl Default for TestExtension {
}
}

impl ChainExtension for TestExtension {
fn call<E: Ext>(func_id: u32, env: Environment<E, InitState>) -> ExtensionResult<RetVal>
impl ChainExtension<Test> for TestExtension {
fn call<E>(func_id: u32, env: Environment<E, InitState>) -> ExtensionResult<RetVal>
where
E: Ext<T = Test>,
<E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,
{
match func_id {
Expand Down