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

Function main

plugins/rest-plugin/src/main.rs:51–120  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49
50#[tokio::main]
51async fn main() -> Result<(), anyhow::Error> {
52 unsafe {
53 // SAFETY:
54 // `std::env::set_var` is unsafe in Rust 2024 because environment variables
55 // are process-global and unsynchronized. Concurrent reads/writes from
56 // multiple threads can cause undefined behavior.
57 //
58 // This call happens at process startup, before any threads are spawned and
59 // before any code that may read environment variables is executed.
60 // Therefore, no concurrent access is possible.
61 std::env::set_var(
62 "CLN_PLUGIN_LOG",
63 "cln_plugin=info,cln_rpc=info,clnrest=debug,warn",
64 )
65 };
66
67 log_panics::init();
68
69 let _ = rustls::crypto::ring::default_provider().install_default();
70
71 let plugin = match Builder::new(tokio::io::stdin(), tokio::io::stdout())
72 .option(OPT_CLNREST_PORT)
73 .option(OPT_CLNREST_CERTS)
74 .option(OPT_CLNREST_PROTOCOL)
75 .option(OPT_CLNREST_HOST)
76 .option(OPT_CLNREST_CORS)
77 .option(OPT_CLNREST_CSP)
78 .option(OPT_CLNREST_SWAGGER)
79 .rpcmethod_from_builder(
80 RpcMethodBuilder::new("clnrest-register-path", register_path)
81 .description("Register a dynamic REST path for clnrest")
82 .usage("path rpc_method [http_method] [rune_required] [rune_restrictions]"),
83 )
84 .subscribe("*", handle_notification)
85 .dynamic()
86 .configure()
87 .await?
88 {
89 Some(p) => p,
90 None => return Ok(()),
91 };
92
93 let clnrest_options = match parse_options(&plugin) {
94 Ok(opts) => opts,
95 Err(e) => return plugin.disable(&e.to_string()).await,
96 };
97
98 let (notify_tx, notify_rx) = mpsc::channel(100);
99
100 let state = PluginState {
101 notification_sender: notify_tx,
102 dyn_router: Arc::new(Mutex::new(matchit::Router::new())),
103 };
104
105 let plugin = plugin.start(state.clone()).await?;
106
107 tokio::select! {
108 _ = plugin.join() => {

Callers

nothing calls this directly

Calls 13

configureMethod · 0.80
optionMethod · 0.80
usageMethod · 0.80
disableMethod · 0.80
parse_optionsFunction · 0.70
initFunction · 0.50
channelClass · 0.50
dynamicMethod · 0.45
subscribeMethod · 0.45
descriptionMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected