use crate::storage::{cache::util::CACHE_KEY_PREFIX_MERKLE, error::StorageResult};
use walletkit_db::Connection;
use super::util::{
cache_entry_times, get_cache_entry, prune_expired_entries, upsert_cache_entry,
};
pub(super) fn get(
conn: &Connection,
valid_until: u64,
) -> StorageResult<Option<Vec<u8>>> {
get_cache_entry(conn, &[CACHE_KEY_PREFIX_MERKLE], valid_until, None)
}
pub(super) fn put(
conn: &Connection,
proof_bytes: &[u8],
now: u64,
ttl_seconds: u64,
) -> StorageResult<()> {
prune_expired_entries(conn, now)?;
let times = cache_entry_times(now, ttl_seconds)?;
upsert_cache_entry(conn, &[CACHE_KEY_PREFIX_MERKLE], proof_bytes, times)
}