multiversx_sc_scenario/api/impl_vh/
vm_hooks_backend.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use multiversx_chain_vm::executor::VMHooks;
use multiversx_sc::api::HandleConstraints;

use crate::debug_executor::StaticVarData;

pub trait VMHooksApiBackend: Clone + Send + Sync + 'static {
    /// We use a single handle type for all handles.
    type HandleType: HandleConstraints;

    /// All communication with the VM happens via this method.
    fn with_vm_hooks<R, F>(f: F) -> R
    where
        F: FnOnce(&dyn VMHooks) -> R;

    fn with_vm_hooks_ctx_1<R, F>(_handle: Self::HandleType, f: F) -> R
    where
        F: FnOnce(&dyn VMHooks) -> R,
    {
        Self::with_vm_hooks(f)
    }

    fn with_vm_hooks_ctx_2<R, F>(_handle1: Self::HandleType, _handle2: Self::HandleType, f: F) -> R
    where
        F: FnOnce(&dyn VMHooks) -> R,
    {
        Self::with_vm_hooks(f)
    }

    fn with_vm_hooks_ctx_3<R, F>(
        _handle1: Self::HandleType,
        _handle2: Self::HandleType,
        _handle3: Self::HandleType,
        f: F,
    ) -> R
    where
        F: FnOnce(&dyn VMHooks) -> R,
    {
        Self::with_vm_hooks(f)
    }

    fn assert_live_handle(_handle: &Self::HandleType) {
        // by default, no check
    }

    /// Static data does not belong to the VM, or to the VM hooks. It belongs to the contract only.
    fn with_static_data<R, F>(f: F) -> R
    where
        F: FnOnce(&StaticVarData) -> R;
}