Skip to main content

multiversx_chain_vm_executor/
breakpoint_value.rs

1/// Represents the reason why execution of a WASM instance was interrupted.
2///
3/// Used by the legacy executor interface to communicate breakpoint causes
4/// between the WASM runtime and the high-level VM.
5///
6/// TODO: move to wasmer-prod, and hide it from the VM implementation.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum BreakpointValueLegacy {
9    /// Lack of a breakpoint
10    None = 0,
11
12    /// Failure indicated by the high-level VM (in the VMHooks).
13    ExecutionFailed = 1,
14
15    /// Stopping execution due to an async call.
16    AsyncCall = 2,
17
18    /// Stopping due to an error signalled by the contract.
19    SignalError = 3,
20
21    /// Stopping due to gas being exhausted.
22    OutOfGas = 4,
23
24    /// Stopping due to over-allocation of WASM memory.
25    MemoryLimit = 5,
26}
27
28impl BreakpointValueLegacy {
29    pub fn as_u64(self) -> u64 {
30        self as u64
31    }
32}
33
34impl TryFrom<u64> for BreakpointValueLegacy {
35    type Error = String;
36
37    fn try_from(value: u64) -> Result<Self, Self::Error> {
38        match value {
39            0 => Ok(BreakpointValueLegacy::None),
40            1 => Ok(BreakpointValueLegacy::ExecutionFailed),
41            2 => Ok(BreakpointValueLegacy::AsyncCall),
42            3 => Ok(BreakpointValueLegacy::SignalError),
43            4 => Ok(BreakpointValueLegacy::OutOfGas),
44            5 => Ok(BreakpointValueLegacy::MemoryLimit),
45            _ => Err("unknown breakpoint".to_string()),
46        }
47    }
48}