MCPcopy Create free account
hub / github.com/ElementsProject/lightning / get_all_rates

Method get_all_rates

plugins/currencyrate-plugin/src/oracle.rs:294–322  ·  view source on GitHub ↗
(&self, currency: &str)

Source from the content-addressed store, hash-verified

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;

Callers 2

listcurrencyratesFunction · 0.80
get_median_rateMethod · 0.80

Calls 2

refresh_currencyMethod · 0.80
mapMethod · 0.80

Tested by

no test coverage detected