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 GasReservationSlot
s,
will be converted to the BTreeMap
of GasReservationState
s.
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, Option<UnreservedReimbursement>), ReservationError>
pub fn unreserve( &mut self, id: ReservationId, ) -> Result<(u64, Option<UnreservedReimbursement>), ReservationError>
Unreserves gas reserved within id
reservation.
Return error if:
- Reservation doesn’t exist.
- Reservation was “unreserved”, so in
GasReservationState::Removed
state. - 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 check_not_used(
&mut self,
id: ReservationId,
) -> Result<&mut bool, ReservationError>
pub fn check_not_used( &mut self, id: ReservationId, ) -> Result<&mut bool, ReservationError>
Check if reservation is not used.
If reservation does not exist returns InvalidReservationId
error.
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 moreSource§impl Debug for GasReserver
impl Debug for GasReserver
Source§impl Decode for GasReserver
impl Decode for GasReserver
Source§fn decode<__CodecInputEdqy: Input>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<Self, Error>
fn decode<__CodecInputEdqy: Input>( __codec_input_edqy: &mut __CodecInputEdqy, ) -> Result<Self, Error>
Attempt to deserialise the value from input.
Source§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
Source§impl Encode for GasReserver
impl Encode for GasReserver
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
If possible give a hint of expected size of the encoding. Read more
Source§fn encode_to<__CodecOutputEdqy: Output + ?Sized>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
Convert self to a slice and append it to the destination.
Source§fn using_encoded<R, F>(&self, f: F) -> R
fn using_encoded<R, F>(&self, f: F) -> R
Convert self to a slice and then invoke the given closure with it.
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
Source§impl PartialEq for GasReserver
impl PartialEq for GasReserver
impl EncodeLike for GasReserver
impl Eq for GasReserver
impl StructuralPartialEq for GasReserver
Auto Trait Implementations§
impl Freeze for GasReserver
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