diff --git a/plugins/src/lib.rs b/plugins/src/lib.rs index 1e576f48d..876bf59d3 100644 --- a/plugins/src/lib.rs +++ b/plugins/src/lib.rs @@ -3,7 +3,7 @@ pub use anyhow::{anyhow, Context}; use futures::sink::SinkExt; extern crate log; use log::trace; -use serde::Deserialize; +use messages::Configuration; use std::collections::HashMap; use std::future::Future; use std::pin::Pin; @@ -210,7 +210,9 @@ where let plugin = Plugin { state: self.state, options: self.options, - configuration: self.configuration.unwrap(), // OK to unwrap, set in handle_init + configuration: self + .configuration + .ok_or(anyhow!("Plugin configuration missing"))?, wait_handle, sender, }; @@ -368,7 +370,9 @@ where { /// The state gets cloned for each request state: S, + /// "options" field of "init" message sent by cln options: Vec, + /// "configuration" field of "init" message sent by cln configuration: Configuration, /// A signal that allows us to wait on the plugin's shutdown. wait_handle: tokio::sync::broadcast::Sender<()>, @@ -662,12 +666,6 @@ where } } -#[derive(Clone, Debug, Deserialize)] -pub struct Configuration { - #[serde(rename = "lightning-dir")] - pub lightning_dir: String, -} - #[cfg(test)] mod test { use super::*; diff --git a/plugins/src/messages.rs b/plugins/src/messages.rs index 4989a09d5..bdd80ce32 100644 --- a/plugins/src/messages.rs +++ b/plugins/src/messages.rs @@ -1,5 +1,4 @@ use crate::options::ConfigOption; -use crate::Configuration; use serde::de::{self, Deserializer}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -67,6 +66,29 @@ pub(crate) struct InitCall { pub(crate) configuration: Configuration, } +#[derive(Clone, Deserialize, Debug)] +pub struct Configuration { + #[serde(rename = "lightning-dir")] + pub lightning_dir: String, + #[serde(rename = "rpc-file")] + pub rpc_file: String, + pub startup: bool, + pub network: String, + pub feature_set: HashMap, + pub proxy: ProxyInfo, + #[serde(rename = "torv3-enabled")] + pub torv3_enabled: bool, + pub always_use_proxy: bool, +} + +#[derive(Clone, Debug, Deserialize)] +pub struct ProxyInfo { + #[serde(alias = "type")] + pub typ: String, + pub address: String, + pub port: i64, +} + #[derive(Debug)] pub enum JsonRpc { Request(usize, R),