Struct cosmwasm_vm::Instance
source · pub struct Instance<A: BackendApi, S: Storage, Q: Querier> { /* private fields */ }
Implementations§
source§impl<A, S, Q> Instance<A, S, Q>where
A: BackendApi + 'static,
S: Storage + 'static,
Q: Querier + 'static,
impl<A, S, Q> Instance<A, S, Q>where
A: BackendApi + 'static,
S: Storage + 'static,
Q: Querier + 'static,
sourcepub fn from_code(
code: &[u8],
backend: Backend<A, S, Q>,
options: InstanceOptions,
memory_limit: Option<Size>
) -> VmResult<Self>
pub fn from_code(
code: &[u8],
backend: Backend<A, S, Q>,
options: InstanceOptions,
memory_limit: Option<Size>
) -> VmResult<Self>
This is the only Instance constructor that can be called from outside of cosmwasm-vm, e.g. in test code that needs a customized variant of cosmwasm_vm::testing::mock_instance*.
pub fn api(&self) -> &A
sourcepub fn recycle(self) -> Option<Backend<A, S, Q>>
pub fn recycle(self) -> Option<Backend<A, S, Q>>
Decomposes this instance into its components. External dependencies are returned for reuse, the rest is dropped.
sourcepub fn required_capabilities(&self) -> HashSet<String>
pub fn required_capabilities(&self) -> HashSet<String>
Returns the features required by this contract.
This is not needed for production because we can do static analysis on the Wasm file before instatiation to obtain this information. It’s only kept because it can be handy for integration testing.
sourcepub fn memory_pages(&self) -> usize
pub fn memory_pages(&self) -> usize
Returns the size of the default memory in pages. This provides a rough idea of the peak memory consumption. Note that Wasm memory always grows in 64 KiB steps (pages) and can never shrink (https://github.com/WebAssembly/design/issues/1300#issuecomment-573867836).
sourcepub fn get_gas_left(&self) -> u64
pub fn get_gas_left(&self) -> u64
Returns the currently remaining gas.
sourcepub fn create_gas_report(&self) -> GasReport
pub fn create_gas_report(&self) -> GasReport
Creates and returns a gas report. This is a snapshot and multiple reports can be created during the lifetime of an instance.
sourcepub fn set_storage_readonly(&mut self, new_value: bool)
pub fn set_storage_readonly(&mut self, new_value: bool)
Sets the readonly storage flag on this instance. Since one instance can be used for multiple calls in integration tests, this should be set to the desired value right before every call.