1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::str;

use super::Context;
use crate::Kernel;
use crate::gas::Gas;
use crate::kernel::{ClassifyResult, Result};

pub fn charge_gas(
    context: Context<'_, impl Kernel>,
    name_off: u32,
    name_len: u32,
    compute: i64,
) -> Result<()> {
    let name =
        str::from_utf8(context.memory.try_slice(name_off, name_len)?).or_illegal_argument()?;
    // Gas charges from actors are always in full gas units. We use milligas internally, so convert here.
    context.kernel.charge_gas(name, Gas::new(compute))
}