Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

contracts: Make ChainExtension trait generic over the runtime #8003

Merged
1 commit merged into from
Feb 3, 2021

Conversation

athei
Copy link
Member

@athei athei commented Jan 29, 2021

This PR changes the ChainExtensions trait to be defined as ChainExtension<C: pallet_contracts::Config>. This is necessary because the ChainExtension::call method has a parameter that is generic over the pallet's configuration. This trait however, only is bound by : frame_system::Config with no way for the ChainExtension implementer to add additional bounds. Therefore calling into any pallet that is not system or contracts would not work because of the missing bounds on that trait.

This PR changes this by giving the implementer the tools to call all runtime functions. A implementation would look like this:

// We assume we are a direct child of the runtime module here
use super::Runtime;

struct TestExtension;

impl ChainExtension<Runtime> for TestExtension {
	fn call<E>(func_id: u32, env: Environment<E, InitState>) -> ExtensionResult<RetVal>
	where
		E: Ext<T = Runtime>,
		<E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,
{
        // The `env` is now connected to the runtime and we can call all pallets of the runtime and pass
        //  around types like `E::T::AccountId` that were read from `env.ext()`.
}

@gregzaitsev : This should fix your problem where you weren't able to pass T::AccountId to your pallet.

@athei athei added A0-please_review Pull request needs code review. B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. labels Jan 29, 2021
@athei
Copy link
Member Author

athei commented Feb 3, 2021

bot merge

@ghost
Copy link

ghost commented Feb 3, 2021

Trying merge.

@ghost ghost merged commit f80d23b into master Feb 3, 2021
@ghost ghost deleted the at-fix-chainext branch February 3, 2021 11:29
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants