pub struct GasReserver { /* private fields */ }
Expand description

Gas reserver.

Controls gas reservations states.

Implementations§

source§

impl GasReserver

source

pub fn new( incoming_dispatch: &IncomingDispatch, map: GasReservationMap, max_reservations: u64 ) -> Self

Creates a new gas reserver.

map, which is a BTreeMap of GasReservationSlots, will be converted to the HashMap of GasReservationStates.

source

pub fn limit_of(&self, reservation_id: &ReservationId) -> Option<u64>

Returns amount of gas in reservation, if exists.

source

pub fn reserve( &mut self, amount: u64, duration: u32 ) -> Result<ReservationId, ReservationError>

Reserves gas.

Creates a new reservation and returns its id.

Returns an error if maximum limit of reservations is reached.

source

pub fn unreserve(&mut self, id: ReservationId) -> Result<u64, ReservationError>

Unreserves gas reserved within id reservation.

Return error if:

  1. Reservation doesn’t exist.
  2. Reservation was “unreserved”, so in GasReservationState::Removed state.
  3. Reservation was marked used.
source

pub fn mark_used(&mut self, id: ReservationId) -> Result<(), ReservationError>

Marks reservation as used.

This allows to avoid double usage of the reservation for sending a new message from execution of message_id of current gas reserver.

source

pub fn nonce(&self) -> ReservationNonce

Returns gas reservations current nonce.

source

pub fn states(&self) -> &GasReservationStates

Gets gas reservations states.

source

pub fn into_map<F>( self, current_block_height: u32, duration_into_expiration: F ) -> GasReservationMap
where F: Fn(u32) -> u32,

Converts current gas reserver into gas reservation map.

Trait Implementations§

source§

impl Clone for GasReserver

source§

fn clone(&self) -> GasReserver

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for GasReserver

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> JsonSchemaMaybe for T