multiversx_chain_vm/host/vm_hooks/
vh_handler.rs1mod vh_blockchain;
2mod vh_call_value;
3mod vh_crypto;
4mod vh_endpoint_arg;
5mod vh_endpoint_finish;
6mod vh_error;
7mod vh_log;
8mod vh_managed_types;
9mod vh_send;
10mod vh_storage;
11
12use multiversx_chain_vm_executor::VMHooksEarlyExit;
13
14use crate::{blockchain::state::AccountData, schedule::GasSchedule};
15
16use super::VMHooksContext;
17
18#[derive(Debug)]
20pub struct VMHooksHandler<C: VMHooksContext> {
21 pub(crate) context: C,
22}
23
24impl<C: VMHooksContext> VMHooksHandler<C> {
25 pub fn new(context: C) -> Self {
26 VMHooksHandler { context }
27 }
28
29 fn gas_schedule(&self) -> &GasSchedule {
31 self.context.gas_schedule()
32 }
33
34 fn use_gas(&mut self, gas: u64) -> Result<(), VMHooksEarlyExit> {
36 self.context.use_gas(gas)
37 }
38
39 fn use_gas_for_data_copy(&mut self, num_bytes_copied: usize) -> Result<(), VMHooksEarlyExit> {
41 self.context.use_gas(
42 num_bytes_copied as u64
43 * self
44 .context
45 .gas_schedule()
46 .base_operation_cost
47 .data_copy_per_byte,
48 )
49 }
50
51 fn current_account_data(&self) -> AccountData {
55 self.context
56 .account_data(&self.context.input_ref().to)
57 .expect("missing current account")
58 }
59}