use serde::Deserialize;
use crate::currency::Lux;
pub const MIN_LIMIT: u64 = 100_000;
pub const DEFAULT_LIMIT_TRANSFER: u64 = 10_000_000;
pub const DEFAULT_LIMIT_DEPLOYMENT: u64 =
1024 * 1024 * 100 + DEFAULT_LIMIT_TRANSFER;
pub const DEFAULT_LIMIT_CALL: u64 = 2_000_000_000;
pub const DEFAULT_LIMIT_STAKE: u64 = 50_000_000;
pub const GAS_PER_DEPLOY_BYTE: u64 = 100;
pub const DEFAULT_PRICE: Lux = 1;
pub const MIN_PRICE_DEPLOYMENT: Lux = 2_000;
#[derive(Debug)]
pub struct Gas {
pub price: Lux,
pub limit: u64,
}
impl Gas {
#[must_use]
pub fn new(limit: u64) -> Self {
Gas {
price: DEFAULT_PRICE,
limit,
}
}
#[must_use]
pub fn is_enough(&self) -> bool {
self.limit >= MIN_LIMIT
}
pub fn set_price<T>(&mut self, price: T)
where
T: Into<Option<Lux>>,
{
self.price = price.into().unwrap_or(DEFAULT_PRICE);
}
#[must_use]
pub fn with_price<T>(mut self, price: T) -> Self
where
T: Into<Lux>,
{
self.price = price.into();
self
}
pub fn set_limit<T>(&mut self, limit: T)
where
T: Into<Option<u64>>,
{
if let Some(limit) = limit.into() {
self.limit = limit;
}
}
}
impl Default for Gas {
fn default() -> Self {
Self::new(DEFAULT_LIMIT_TRANSFER)
}
}
#[derive(Debug, Deserialize)]
pub struct MempoolGasPrices {
pub average: Lux,
pub max: Lux,
pub median: Lux,
pub min: Lux,
}