Function gstd::exec::reserve_gas

source ·
pub fn reserve_gas(amount: u64, duration: u32) -> Result<ReservationId, Error>
Expand description

Reserve the amount of gas for further usage.

duration is the block count within which the reserve must be used.

This function returns ReservationId, which one can use for gas unreserving.

§Examples

Reserve 50 million of gas for seven blocks:

use gcore::{exec, ReservationId};

static mut RESERVED: ReservationId = ReservationId::zero();

#[no_mangle]
extern "C" fn init() {
    unsafe { RESERVED = exec::reserve_gas(50_000_000, 7).unwrap() };
}

#[no_mangle]
extern "C" fn handle() {
    exec::unreserve_gas(unsafe { RESERVED }).expect("Unable to unreserve");
}

§See also