mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 14:25:41 +00:00
Add get_global for Sandbox (#4756)
* Add `get_global` for `Sandbox` This pr adds `get_global` to retrieve a `global` variable from an instantiated sandbox wasm blob. * Bump `spec_version` * Update primitives/wasm-interface/src/lib.rs Co-Authored-By: Sergei Pepyakin <sergei@parity.io> * `get_global` -> `get_global_val` Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com> Co-authored-by: Gavin Wood <github@gavwood.com>
This commit is contained in:
@@ -12,6 +12,7 @@ sp-core = { version = "2.0.0", default-features = false, path = "../core" }
|
||||
sp-std = { version = "2.0.0", default-features = false, path = "../std" }
|
||||
libsecp256k1 = { version = "0.3.4", optional = true }
|
||||
sp-state-machine = { version = "0.8", optional = true, path = "../../primitives/state-machine" }
|
||||
sp-wasm-interface = { version = "2.0.0", path = "../../primitives/wasm-interface", default-features = false }
|
||||
sp-runtime-interface = { version = "2.0.0", default-features = false, path = "../runtime-interface" }
|
||||
sp-trie = { version = "2.0.0", optional = true, path = "../../primitives/trie" }
|
||||
sp-externalities = { version = "0.8.0", optional = true, path = "../externalities" }
|
||||
@@ -29,6 +30,7 @@ std = [
|
||||
"libsecp256k1",
|
||||
"sp-runtime-interface/std",
|
||||
"sp-externalities",
|
||||
"sp-wasm-interface/std",
|
||||
"log",
|
||||
]
|
||||
|
||||
|
||||
@@ -850,6 +850,14 @@ pub trait Sandbox {
|
||||
fn instance_teardown(&mut self, instance_idx: u32) {
|
||||
self.sandbox().instance_teardown(instance_idx).expect("Failed to teardown sandbox instance")
|
||||
}
|
||||
|
||||
/// Get the value from a global with the given `name`. The sandbox is determined by the given
|
||||
/// `instance_idx`.
|
||||
///
|
||||
/// Returns `Some(_)` when the requested global variable could be found.
|
||||
fn get_global_val(&mut self, instance_idx: u32, name: &str) -> Option<sp_wasm_interface::Value> {
|
||||
self.sandbox().get_global_val(instance_idx, name).expect("Failed to get global from sandbox")
|
||||
}
|
||||
}
|
||||
|
||||
/// Allocator used by Substrate when executing the Wasm runtime.
|
||||
|
||||
Reference in New Issue
Block a user