use crate::error::AdapterError;
#[async_trait::async_trait]
pub trait HeatSink: Send + Sync {
async fn announce_heat(&self, origin_hash: u64, rate: f64) -> Result<(), AdapterError>;
async fn withdraw_heat(&self, origin_hash: u64) -> Result<(), AdapterError>;
async fn announce_heat_batch(
&self,
updates: &[(u64, Option<f64>)],
) -> Result<(), AdapterError> {
for &(origin_hash, rate_opt) in updates {
match rate_opt {
Some(rate) => self.announce_heat(origin_hash, rate).await?,
None => self.withdraw_heat(origin_hash).await?,
}
}
Ok(())
}
}
#[async_trait::async_trait]
pub trait BlobHeatSink: Send + Sync {
async fn announce_blob_heat(&self, hash: [u8; 32], rate: f64) -> Result<(), AdapterError>;
async fn withdraw_blob_heat(&self, hash: [u8; 32]) -> Result<(), AdapterError>;
async fn announce_blob_heat_batch(
&self,
updates: &[([u8; 32], Option<f64>)],
) -> Result<(), AdapterError> {
for &(hash, rate_opt) in updates {
match rate_opt {
Some(rate) => self.announce_blob_heat(hash, rate).await?,
None => self.withdraw_blob_heat(hash).await?,
}
}
Ok(())
}
}