(&self, currency: &str)
| 292 | } |
| 293 | |
| 294 | pub async fn get_all_rates(&self, currency: &str) -> Result<Vec<SourceResult>, anyhow::Error> { |
| 295 | self.refresh_currency(currency).await?; |
| 296 | |
| 297 | let results = { |
| 298 | let mut inner = self.inner.lock().await; |
| 299 | let cache = inner |
| 300 | .currencies |
| 301 | .entry(currency.to_owned()) |
| 302 | .or_insert_with(CurrencyCache::new); |
| 303 | |
| 304 | cache |
| 305 | .prices |
| 306 | .iter() |
| 307 | .filter(|(_, price_cache)| price_cache.timestamp + SERVE_TTL > Instant::now()) |
| 308 | .map(|(name, price)| SourceResult { |
| 309 | name: name.clone(), |
| 310 | price: price.price, |
| 311 | }) |
| 312 | .collect::<Vec<_>>() |
| 313 | }; |
| 314 | |
| 315 | if results.is_empty() { |
| 316 | return Err(anyhow::anyhow!( |
| 317 | "no results for `{currency}`, is the currency supported? Check the logs!" |
| 318 | )); |
| 319 | } |
| 320 | |
| 321 | Ok(results) |
| 322 | } |
| 323 | |
| 324 | pub async fn get_median_rate(&self, currency: &str) -> Result<f64, anyhow::Error> { |
| 325 | let inner = self.inner.lock().await; |
no test coverage detected