mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 15:41:02 +00:00
contracts: Allow runtime authors to define a chain extension (#7548)
* Make host functions return TrapReason This avoids the need to manually store any trap reasons to the `Runtime` from the host function. This adds the following benefits: * It properly composes with the upcoming chain extensions * Missing to set a trap value is now a compile error * Add chain extension The chain extension is a way for the contract author to add new host functions for contracts to call. * Add tests for chain extensions * Fix regression in set_rent.wat fixture Not all offsets where properly updated when changing the fixtures for the new salt on instantiate. * Pre-charge a weight amount based off the specified length * Improve fn write docs * Renamed state to phantom * Fix typo
This commit is contained in:
committed by
GitHub
parent
e3e651f72c
commit
51c37ecc15
@@ -19,10 +19,11 @@
|
||||
//! wasm module before execution. It also extracts some essential information
|
||||
//! from a module.
|
||||
|
||||
use crate::wasm::env_def::ImportSatisfyCheck;
|
||||
use crate::wasm::PrefabWasmModule;
|
||||
use crate::{Schedule, Config};
|
||||
|
||||
use crate::{
|
||||
Schedule, Config,
|
||||
chain_extension::ChainExtension,
|
||||
wasm::{PrefabWasmModule, env_def::ImportSatisfyCheck},
|
||||
};
|
||||
use parity_wasm::elements::{self, Internal, External, MemoryType, Type, ValueType};
|
||||
use pwasm_utils;
|
||||
use sp_std::prelude::*;
|
||||
@@ -355,6 +356,12 @@ impl<'a, T: Config> ContractModule<'a, T> {
|
||||
return Err("module imports `seal_println` but debug features disabled");
|
||||
}
|
||||
|
||||
if !T::ChainExtension::enabled() &&
|
||||
import.field().as_bytes() == b"seal_call_chain_extension"
|
||||
{
|
||||
return Err("module uses chain extensions but chain extensions are disabled");
|
||||
}
|
||||
|
||||
if import_fn_banlist.iter().any(|f| import.field().as_bytes() == *f)
|
||||
|| !C::can_satisfy(import.field().as_bytes(), func_ty)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user