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

Function gather_sources

plugins/currencyrate-plugin/src/main.rs:338–376  ·  view source on GitHub ↗
(
    plugin: &ConfiguredPlugin<PluginState, tokio::io::Stdin, tokio::io::Stdout>,
    has_proxy: bool,
)

Source from the content-addressed store, hash-verified

336 Err(anyhow!("Could not parse proxy value: {proxy_str}"))
337}
338fn gather_sources(
339 plugin: &ConfiguredPlugin<PluginState, tokio::io::Stdin, tokio::io::Stdout>,
340 has_proxy: bool,
341) -> Result<Vec<Source>, anyhow::Error> {
342 let mut result = Vec::new();
343
344 let source_opts = plugin.option_str("currencyrate-add-source").unwrap();
345 if let Some(sources) = source_opts {
346 let sources_arr = sources
347 .as_str_arr()
348 .ok_or(anyhow!("currencyrate-add-source is not a string array"))?;
349 for source in sources_arr {
350 let parts: Vec<&str> = source.splitn(3, ',').collect();
351 if parts.len() != 3 {
352 return Err(anyhow!("Invalid source format: {source}"));
353 }
354 let source = Source::new(parts[0], parts[1], parts[2].split(',').collect());
355 result.push(source);
356 }
357 }
358
359 add_default_sources(&mut result, has_proxy);
360
361 let disable_sources = plugin.option_str("currencyrate-disable-source").unwrap();
362 if let Some(dis_sorc) = disable_sources {
363 let disable_sources_arr = dis_sorc
364 .as_str_arr()
365 .ok_or(anyhow!("currencyrate-disable-source is not a string array"))?;
366 for source in disable_sources_arr {
367 result.retain(|s| s.name() != source);
368 }
369 }
370
371 if result.is_empty() {
372 return Err(anyhow!("No sources configured"));
373 }
374
375 Ok(result)
376}
377
378fn add_default_sources(result: &mut Vec<Source>, has_proxy: bool) {
379 let coingecko = Source::new(

Callers 1

mainFunction · 0.85

Calls 5

add_default_sourcesFunction · 0.85
option_strMethod · 0.80
as_str_arrMethod · 0.80
unwrapMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected