pub struct GasCounter { /* private fields */ }
Expand description
Gas counter with some predefined maximum gas.
Copy
and Clone
traits aren’t implemented for the type (however could be)
in order to make the data only moveable, preventing explicit and implicit copying.
Implementations§
Source§impl GasCounter
impl GasCounter
Sourcepub fn charge<T: Into<u64> + Copy>(&mut self, amount: T) -> ChargeResult
pub fn charge<T: Into<u64> + Copy>(&mut self, amount: T) -> ChargeResult
Account for used gas.
If there is no enough gas, then makes saturating charge and returns NotEnough
.
Else charges gas and returns Enough
.
Sourcepub fn charge_if_enough<T: Into<u64> + Copy>(
&mut self,
amount: T,
) -> ChargeResult
pub fn charge_if_enough<T: Into<u64> + Copy>( &mut self, amount: T, ) -> ChargeResult
Account for used gas.
If there is no enough gas, then does nothing and returns ChargeResult::NotEnough
.
Else charges gas and returns ChargeResult::Enough
.
Sourcepub fn increase(&mut self, amount: u64, _token: UnreservedReimbursement) -> bool
pub fn increase(&mut self, amount: u64, _token: UnreservedReimbursement) -> bool
Increase left gas by amount
.
Called when gas unreservation is occurred.
We don’t decrease burn
counter because GasTree
manipulation is handled by separated function
Sourcepub fn reduce(&mut self, amount: u64) -> ChargeResult
pub fn reduce(&mut self, amount: u64) -> ChargeResult
Reduce gas by amount
.
Called when message is sent to another program, so the gas amount
is sent to
receiving program.
Or called when gas reservation is occurred.
In case of gas reservation:
We don’t increase burn
counter because GasTree
manipulation is handled by separated function