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
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_schedule::GasAlgebra;
use move_vm_runtime::native_functions::NativeContext;
use move_vm_types::{
gas_schedule::NativeCostIndex,
loaded_data::runtime_types::Type,
natives::function::{native_gas, NativeResult},
pop_arg,
values::Value,
};
use smallvec::smallvec;
use std::collections::VecDeque;
pub fn native_write_to_event_store(
context: &mut NativeContext,
mut ty_args: Vec<Type>,
mut arguments: VecDeque<Value>,
) -> PartialVMResult<NativeResult> {
debug_assert!(ty_args.len() == 1);
debug_assert!(arguments.len() == 3);
let ty = ty_args.pop().unwrap();
let msg = arguments.pop_back().unwrap();
let seq_num = pop_arg!(arguments, u64);
let guid = pop_arg!(arguments, Vec<u8>);
let cost = native_gas(
context.cost_table(),
NativeCostIndex::EMIT_EVENT,
msg.size().get() as usize,
);
if !context.save_event(guid, seq_num, ty, msg)? {
return Ok(NativeResult::err(cost, 0));
}
Ok(NativeResult::ok(cost, smallvec![]))
}