Struct gear_core::reservation::GasReserver
source · pub struct GasReserver { /* private fields */ }Expand description
Gas reserver.
Controls gas reservations states.
Implementations§
source§impl GasReserver
impl GasReserver
sourcepub fn new(
incoming_dispatch: &IncomingDispatch,
map: GasReservationMap,
max_reservations: u64
) -> Self
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.
sourcepub fn limit_of(&self, reservation_id: &ReservationId) -> Option<u64>
pub fn limit_of(&self, reservation_id: &ReservationId) -> Option<u64>
Returns amount of gas in reservation, if exists.
sourcepub fn reserve(
&mut self,
amount: u64,
duration: u32
) -> Result<ReservationId, ReservationError>
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.
sourcepub fn unreserve(&mut self, id: ReservationId) -> Result<u64, ReservationError>
pub fn unreserve(&mut self, id: ReservationId) -> Result<u64, ReservationError>
Unreserves gas reserved within id reservation.
Return error if:
- Reservation doesn’t exist.
- Reservation was “unreserved”, so in
GasReservationState::Removedstate. - Reservation was marked used.
sourcepub fn mark_used(&mut self, id: ReservationId) -> Result<(), ReservationError>
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.
sourcepub fn nonce(&self) -> ReservationNonce
pub fn nonce(&self) -> ReservationNonce
Returns gas reservations current nonce.
sourcepub fn states(&self) -> &GasReservationStates
pub fn states(&self) -> &GasReservationStates
Gets gas reservations states.
Trait Implementations§
source§impl Clone for GasReserver
impl Clone for GasReserver
source§fn clone(&self) -> GasReserver
fn clone(&self) -> GasReserver
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl RefUnwindSafe for GasReserver
impl Send for GasReserver
impl Sync for GasReserver
impl Unpin for GasReserver
impl UnwindSafe for GasReserver
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more