Function gstd::exec::gas_available

source ·
pub fn gas_available() -> u64
Expand description

Get the current amount of gas available for execution.

Each message processing consumes gas on instructions execution and memory allocations. This function returns a value of the gas available for spending during the current execution. Its use may help avoid unexpected behaviors during the program execution in case insufficient gas is available.

§Examples

Do the job while the amount of available gas is more than 1000:

use gcore::exec;

#[no_mangle]
extern "C" fn handle() {
    while exec::gas_available() > 1000 {
        // ...
    }
}