multiversx_chain_vm/host/vm_hooks/vh_handler/
vh_log.rs1use multiversx_chain_vm_executor::VMHooksEarlyExit;
2
3use crate::{host::context::TxLog, host::vm_hooks::VMHooksContext, types::RawHandle};
4
5use super::VMHooksHandler;
6
7impl<C: VMHooksContext> VMHooksHandler<C> {
8 pub fn managed_write_log(
9 &mut self,
10 topics_handle: RawHandle,
11 data_handle: RawHandle,
12 ) -> Result<(), VMHooksEarlyExit> {
13 self.use_gas(self.gas_schedule().base_ops_api_cost.log)?;
14
15 let (topics, topic_bytes_copied) = self
16 .context
17 .m_types_lock()
18 .mb_get_vec_of_bytes(topics_handle);
19 let single_data_field = self.context.m_types_lock().mb_get(data_handle).to_vec();
20
21 self.use_gas_for_data_copy(topic_bytes_copied + single_data_field.len())?;
22
23 self.context.push_tx_log(TxLog {
24 address: self.context.current_address().clone(),
25 endpoint: self.context.input_ref().func_name.clone(),
26 topics,
27 data: vec![single_data_field],
28 });
29 Ok(())
30 }
31}