cln4rust icon indicating copy to clipboard operation
cln4rust copied to clipboard

improve the way to access to the option and configuration value inside the plugin

Open vincenzopalazzo opened this issue 2 years ago • 0 comments

Take the value from the configuration plugin usually inside the init method is painful

+        .on_init(&|plugin| -> Value {
+            plugin.log(LogLevel::Debug, "Custom init method called");
+            // FIXME: improve the get option plugin API
+            let conf = if let Some(conf_plugin) = &plugin.conf {
+                conf_plugin
+            } else {
+                panic!("this should never happen")
+            };
+            let server_port = conf.options[0].to_owned();
+            let server_port: i32 = from_value(server_port).unwrap();
+            if server_port >= 0 {
+                plugin.log(LogLevel::Info, "running rest server on port {port}");
+                let path = conf.configuration.lightning_dir.as_str();
+                run_rocket(path);
+            }
+            json_utils::init_payload()
+        })

vincenzopalazzo avatar Oct 27 '22 08:10 vincenzopalazzo