use alloy_primitives::Address;
use crate::FeedId;
#[derive(Clone, Debug)]
pub struct FeedConfig {
pub proxy: Address,
pub id: Option<FeedId>,
pub label: Option<String>,
pub base: Option<String>,
pub quote: Option<String>,
pub staleness: StalenessPolicy,
}
impl Default for FeedConfig {
fn default() -> Self {
Self {
proxy: Address::ZERO,
id: None,
label: None,
base: None,
quote: None,
staleness: StalenessPolicy::default(),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct StalenessPolicy {
max_age_secs: Option<u64>,
allow_zero_or_negative_answer: bool,
}
impl StalenessPolicy {
pub fn max_age(max_age_secs: u64) -> Self {
Self {
max_age_secs: Some(max_age_secs),
allow_zero_or_negative_answer: false,
}
}
pub fn allow_zero_or_negative_answer(mut self, allow: bool) -> Self {
self.allow_zero_or_negative_answer = allow;
self
}
pub(crate) fn max_age_secs(&self) -> Option<u64> {
self.max_age_secs
}
pub(crate) fn allows_zero_or_negative_answer(&self) -> bool {
self.allow_zero_or_negative_answer
}
}