Struct web30::gas_estimator::GasTracker
source · pub struct GasTracker { /* private fields */ }
Expand description
A struct for storing gas prices and estimating when it’s a good idea to perform some gas intensive operation
Implementations§
source§impl GasTracker
impl GasTracker
sourcepub fn new(size: usize) -> Self
pub fn new(size: usize) -> Self
create a new gas tracker with size internal sample size and number of samples before which it will not give an estimate
sourcepub fn get_current_size(&self) -> usize
pub fn get_current_size(&self) -> usize
Returns the current number of stored gas prices
sourcepub fn get_history(&self) -> VecDeque<GasPriceEntry>
pub fn get_history(&self) -> VecDeque<GasPriceEntry>
Returns a copy of the stored gas price history
sourcepub fn expand_history_size(&mut self, size: usize)
pub fn expand_history_size(&mut self, size: usize)
Increases the history size limit returns an error if the history is already larger than the input size
sourcepub fn latest_gas_price(&self) -> Option<Uint256>
pub fn latest_gas_price(&self) -> Option<Uint256>
Gets the most recently stored gas price
sourcepub async fn sample(web30: &Web3) -> Option<GasPriceEntry>
pub async fn sample(web30: &Web3) -> Option<GasPriceEntry>
Samples Ethereum gas prices and creates a new GasPriceEntry on success If you are not running GasTracker multi-threaded, consider sample_and_update()
sourcepub fn update(&mut self, sample: GasPriceEntry)
pub fn update(&mut self, sample: GasPriceEntry)
Updates the latest gas price and adds it to the array To obtain a sample, use GasTracker::sample(), or use sample_and_update() if you are not running the GasTracker multi-threaded
sourcepub async fn sample_and_update(&mut self, web30: &Web3) -> Option<Uint256>
pub async fn sample_and_update(&mut self, web30: &Web3) -> Option<Uint256>
Gets the latest gas price and adds it to the array if this fails the sample is skipped, returns a gas price if one is successfully added
sourcepub fn get_acceptable_gas_price(&self, percentage: f32) -> Option<Uint256>
pub fn get_acceptable_gas_price(&self, percentage: f32) -> Option<Uint256>
Look through all the gas prices in the history range and determine the highest acceptable price to pay as provided by a user percentage
Trait Implementations§
source§impl Clone for GasTracker
impl Clone for GasTracker
source§fn clone(&self) -> GasTracker
fn clone(&self) -> GasTracker
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for GasTracker
impl Debug for GasTracker
source§impl Default for GasTracker
impl Default for GasTracker
source§fn default() -> GasTracker
fn default() -> GasTracker
source§impl PartialEq for GasTracker
impl PartialEq for GasTracker
source§fn eq(&self, other: &GasTracker) -> bool
fn eq(&self, other: &GasTracker) -> bool
self
and other
values to be equal, and is used
by ==
.impl Eq for GasTracker
impl StructuralPartialEq for GasTracker
Auto Trait Implementations§
impl Freeze for GasTracker
impl RefUnwindSafe for GasTracker
impl Send for GasTracker
impl Sync for GasTracker
impl Unpin for GasTracker
impl UnwindSafe for GasTracker
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
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.