pub struct WasmToolRunner { /* private fields */ }Expand description
WASM tool runner.
When the wasm-sandbox feature is enabled, this uses Wasmtime
for actual WASM execution. Without the feature, all tool loads
are rejected with WasmError::RuntimeUnavailable.
Implementations§
Source§impl WasmToolRunner
impl WasmToolRunner
Sourcepub fn new(config: WasmSandboxConfig) -> Self
pub fn new(config: WasmSandboxConfig) -> Self
Create a new WASM tool runner with the given configuration.
Sourcepub fn set_chain_manager(&mut self, cm: Arc<ChainManager>)
pub fn set_chain_manager(&mut self, cm: Arc<ChainManager>)
Attach a chain manager for exochain event logging.
Sourcepub fn set_governance_engine(&mut self, ge: Arc<GovernanceEngine>)
pub fn set_governance_engine(&mut self, ge: Arc<GovernanceEngine>)
Attach a governance engine for pre-execution gating.
Sourcepub fn config(&self) -> &WasmSandboxConfig
pub fn config(&self) -> &WasmSandboxConfig
Get the sandbox configuration.
Sourcepub fn validate_wasm(
&self,
wasm_bytes: &[u8],
) -> Result<WasmValidation, WasmError>
pub fn validate_wasm( &self, wasm_bytes: &[u8], ) -> Result<WasmValidation, WasmError>
Validate a WASM module’s bytes without loading it.
Checks module size, magic bytes, and (when the runtime is available) uses wasmtime::Module::validate() for full validation.
Sourcepub fn load_tool(
&self,
name: &str,
wasm_bytes: &[u8],
) -> Result<WasmTool, WasmError>
pub fn load_tool( &self, name: &str, wasm_bytes: &[u8], ) -> Result<WasmTool, WasmError>
Load a WASM tool from bytes.
Validates the module, computes a SHA-256 hash, and (with wasm-sandbox)
compiles it with the Wasmtime engine.
Sourcepub fn execute(
&self,
_tool: &WasmTool,
_input: Value,
) -> Result<WasmToolResult, WasmError>
pub fn execute( &self, _tool: &WasmTool, _input: Value, ) -> Result<WasmToolResult, WasmError>
Execute a loaded WASM tool synchronously.
Creates an isolated store with fuel metering and memory limits,
compiles the tool’s module bytes, and calls _start or execute.
No host filesystem access is provided – the instance receives
an empty set of imports.
For WASI-aware execution with stdio pipes, use [execute_bytes].
Sourcepub fn execute_sync(
&self,
name: &str,
wasm_bytes: &[u8],
_input: Value,
) -> Result<WasmToolResult, WasmError>
pub fn execute_sync( &self, name: &str, wasm_bytes: &[u8], _input: Value, ) -> Result<WasmToolResult, WasmError>
Execute raw WASM bytes synchronously without WASI.
This is the sync K3 execution path. It creates a fresh Wasmtime
store with fuel metering and memory limits, instantiates the
module with no imports (no filesystem, no network), and
calls _start or run.
Returns WasmToolResult on success or a typed WasmError
on fuel exhaustion, memory overflow, or compilation failure.
Sourcepub async fn execute_bytes(
&self,
name: &str,
wasm_bytes: &[u8],
input: Value,
) -> Result<WasmToolResult, WasmError>
pub async fn execute_bytes( &self, name: &str, wasm_bytes: &[u8], input: Value, ) -> Result<WasmToolResult, WasmError>
Compile and execute WASM bytes in one shot.
This is the primary execution path for K3. It accepts raw WASM
bytes (binary or WAT text), compiles them with the engine, creates
an isolated WASI store with fuel metering, serializes input as
JSON to the module’s stdin, calls _start (WASI preview1) or
execute, and reads stdout/stderr.
For cached execution with pre-compiled modules, see K4.
Auto Trait Implementations§
impl !RefUnwindSafe for WasmToolRunner
impl !UnwindSafe for WasmToolRunner
impl Freeze for WasmToolRunner
impl Send for WasmToolRunner
impl Sync for WasmToolRunner
impl Unpin for WasmToolRunner
impl UnsafeUnpin for WasmToolRunner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more