()
| 39 | |
| 40 | #[tokio::main(flavor = "current_thread")] |
| 41 | async fn main() -> Result<()> { |
| 42 | unsafe { |
| 43 | // SAFETY: |
| 44 | // `std::env::set_var` is unsafe in Rust 2024 because environment variables |
| 45 | // are process-global and unsynchronized. Concurrent reads/writes from |
| 46 | // multiple threads can cause undefined behavior. |
| 47 | // |
| 48 | // This call happens at process startup, before any threads are spawned and |
| 49 | // before any code that may read environment variables is executed. |
| 50 | // Therefore, no concurrent access is possible. |
| 51 | std::env::set_var( |
| 52 | "CLN_PLUGIN_LOG", |
| 53 | "cln_plugin=info,cln_rpc=info,cln_grpc=debug,debug", |
| 54 | ) |
| 55 | }; |
| 56 | |
| 57 | let directory = std::env::current_dir()?; |
| 58 | |
| 59 | let plugin = match Builder::new(tokio::io::stdin(), tokio::io::stdout()) |
| 60 | .option(OPTION_GRPC_PORT) |
| 61 | .option(OPTION_GRPC_HOST) |
| 62 | .option(OPTION_GRPC_MSG_BUFFER_SIZE) |
| 63 | // TODO: Use the catch-all subscribe method |
| 64 | // However, doing this breaks the plugin at the time begin |
| 65 | // We should fix this |
| 66 | // .subscribe("*", handle_notification) |
| 67 | .subscribe("balance_snapshot", handle_notification) |
| 68 | .subscribe("block_added", handle_notification) |
| 69 | .subscribe("channel_open_failed", handle_notification) |
| 70 | .subscribe("channel_opened", handle_notification) |
| 71 | .subscribe("channel_state_changed", handle_notification) |
| 72 | .subscribe("coin_movement", handle_notification) |
| 73 | .subscribe("connect", handle_notification) |
| 74 | .subscribe("custommsg", handle_notification) |
| 75 | .subscribe("disconnect", handle_notification) |
| 76 | .subscribe("forward_event", handle_notification) |
| 77 | .subscribe("invoice_creation", handle_notification) |
| 78 | .subscribe("invoice_payment", handle_notification) |
| 79 | .subscribe("onionmessage_forward_fail", handle_notification) |
| 80 | .subscribe("openchannel_peer_sigs", handle_notification) |
| 81 | .subscribe("pay_part_start", handle_notification) |
| 82 | .subscribe("pay_part_end", handle_notification) |
| 83 | .subscribe("plugin_started", handle_notification) |
| 84 | .subscribe("plugin_stopped", handle_notification) |
| 85 | .subscribe("sendpay_failure", handle_notification) |
| 86 | .subscribe("sendpay_success", handle_notification) |
| 87 | .subscribe("warning", handle_notification) |
| 88 | .configure() |
| 89 | .await? |
| 90 | { |
| 91 | Some(p) => p, |
| 92 | None => return Ok(()), |
| 93 | }; |
| 94 | |
| 95 | let bind_port: i64 = plugin.option(&OPTION_GRPC_PORT).unwrap(); |
| 96 | let bind_host: String = plugin.option(&OPTION_GRPC_HOST).unwrap(); |
| 97 | let buffer_size: i64 = plugin.option(&OPTION_GRPC_MSG_BUFFER_SIZE).unwrap(); |
| 98 | let buffer_size = match usize::try_from(buffer_size) { |
nothing calls this directly
no test coverage detected