use serde::Deserialize;
use crate::utils::dec::Dec;
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct GasAuction {
pub start_time_seconds: u64,
pub duration_seconds: u64,
pub start_gas: Dec,
#[serde(default)]
pub current_gas: Option<Dec>,
#[serde(default)]
pub end_gas: Option<Dec>,
}
impl GasAuction {
#[must_use]
pub const fn ends_at(&self) -> u64 {
self.start_time_seconds.saturating_add(self.duration_seconds)
}
#[must_use]
pub const fn is_running(&self, now_seconds: u64) -> bool {
now_seconds >= self.start_time_seconds && now_seconds < self.ends_at()
}
}
#[cfg(test)]
#[path = "tests/auction.rs"]
mod tests;