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
use multiversx_sc::api::{CallValueApi, CallValueApiImpl, HandleConstraints};

use crate::api::{VMHooksApi, VMHooksApiBackend};

impl<VHB: VMHooksApiBackend> CallValueApi for VMHooksApi<VHB> {
    type CallValueApiImpl = Self;

    fn call_value_api_impl() -> Self::CallValueApiImpl {
        Self::api_impl()
    }
}

impl<VHB: VMHooksApiBackend> CallValueApiImpl for VMHooksApi<VHB> {
    fn check_not_payable(&self) {
        self.with_vm_hooks(|vh| vh.check_no_payment())
    }

    fn load_egld_value(&self, dest: Self::BigIntHandle) {
        self.assert_live_handle(&dest);
        self.with_vm_hooks(|vh| vh.big_int_get_call_value(dest.get_raw_handle_unchecked()));
    }

    fn load_all_esdt_transfers(&self, dest_handle: Self::ManagedBufferHandle) {
        self.assert_live_handle(&dest_handle);
        self.with_vm_hooks(|vh| {
            vh.managed_get_multi_esdt_call_value(dest_handle.get_raw_handle_unchecked())
        });
    }

    fn esdt_num_transfers(&self) -> usize {
        self.with_vm_hooks(|vh| vh.get_num_esdt_transfers()) as usize
    }
}