use std::time::Duration;
use crate::{
store::LightStore,
verifier::types::{Height, LightBlock, Status, Time},
};
pub fn trusted_store_contains_block_at_target_height(
light_store: &dyn LightStore,
target_height: Height,
) -> bool {
light_store.get(target_height, Status::Verified).is_some()
|| light_store.get(target_height, Status::Trusted).is_some()
}
pub fn is_within_trust_period(
light_block: &LightBlock,
trusting_period: Duration,
now: Time,
) -> bool {
let header_time = light_block.signed_header.header.time;
match now - trusting_period {
Ok(start) => header_time > start,
Err(_) => false,
}
}
pub fn light_store_contains_block_within_trusting_period(
light_store: &dyn LightStore,
trusting_period: Duration,
now: Time,
) -> bool {
light_store
.all(Status::Trusted)
.any(|lb| is_within_trust_period(&lb, trusting_period, now))
}