mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
contracts: Make ChainExtension trait generic over the runtime (#8003)
This commit is contained in:
committed by
GitHub
parent
06b432caba
commit
26b093ea8a
@@ -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.
|
||||
@@ -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
|
||||
@@ -91,8 +91,9 @@ pub trait ChainExtension {
|
||||
/// 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.
|
||||
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.
|
||||
@@ -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
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user