()
| 34 | |
| 35 | #[tokio::main(flavor = "current_thread")] |
| 36 | async fn main() -> Result<(), anyhow::Error> { |
| 37 | unsafe { |
| 38 | // SAFETY: |
| 39 | // `std::env::set_var` is unsafe in Rust 2024 because environment variables |
| 40 | // are process-global and unsynchronized. Concurrent reads/writes from |
| 41 | // multiple threads can cause undefined behavior. |
| 42 | // |
| 43 | // This call happens at process startup, before any threads are spawned and |
| 44 | // before any code that may read environment variables is executed. |
| 45 | // Therefore, no concurrent access is possible. |
| 46 | std::env::set_var( |
| 47 | "CLN_PLUGIN_LOG", |
| 48 | "cln_plugin=info,cln_rpc=info,cln_currencyrate=debug,warn", |
| 49 | ) |
| 50 | }; |
| 51 | |
| 52 | log_panics::init(); |
| 53 | |
| 54 | let _ = rustls::crypto::ring::default_provider().install_default(); |
| 55 | |
| 56 | let add_source_opt = StringArrayConfigOption::new_str_arr_no_default( |
| 57 | "currencyrate-add-source", |
| 58 | "A source for cln-currencyrate to fetch price data from in the format of `NAME,URL,MEMBERS`", |
| 59 | ); |
| 60 | let disable_source_opt = StringArrayConfigOption::new_str_arr_no_default( |
| 61 | "currencyrate-disable-source", |
| 62 | "The name of the cln-currencyrate source to disable", |
| 63 | ); |
| 64 | |
| 65 | let Some(plugin) = Builder::new(tokio::io::stdin(), tokio::io::stdout()) |
| 66 | .option(add_source_opt) |
| 67 | .option(disable_source_opt) |
| 68 | .rpcmethod_from_builder( |
| 69 | RpcMethodBuilder::new("currencyconvert", currencyconvert) |
| 70 | .description( |
| 71 | "Converts the given amount and currency into msats, using the |
| 72 | median from currencyrates results", |
| 73 | ) |
| 74 | .usage("amount currency"), |
| 75 | ) |
| 76 | .rpcmethod_from_builder( |
| 77 | RpcMethodBuilder::new("listcurrencyrates", listcurrencyrates) |
| 78 | .description("Returns the BTC price for the currency from every source") |
| 79 | .usage("currency"), |
| 80 | ) |
| 81 | .rpcmethod_from_builder( |
| 82 | RpcMethodBuilder::new("currencyrate", currencyrate) |
| 83 | .description( |
| 84 | "Provides the conversion of one BTC into the given currency, using the median of the available exchange-rate sources", |
| 85 | ) |
| 86 | .usage("currency"), |
| 87 | ) |
| 88 | .dynamic() |
| 89 | .configure() |
| 90 | .await? |
| 91 | else { |
| 92 | return Ok(()); |
| 93 | }; |
nothing calls this directly
no test coverage detected