Skip to content

Commit

Permalink
cln-plugin: Configuration struct
Browse files Browse the repository at this point in the history
Represents the "configuration" part of the "init" message during
plugin initialization.

Changelog-Added: cln_plugin: persist cln configuration from init msg
  • Loading branch information
justinmoon committed May 21, 2022
1 parent 1c13c65 commit 1c39564
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
14 changes: 6 additions & 8 deletions plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -368,7 +370,9 @@ where
{
/// The state gets cloned for each request
state: S,
/// "options" field of "init" message sent by cln
options: Vec<ConfigOption>,
/// "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<()>,
Expand Down Expand Up @@ -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::*;
Expand Down
24 changes: 23 additions & 1 deletion plugins/src/messages.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::options::ConfigOption;
use crate::Configuration;
use serde::de::{self, Deserializer};
use serde::{Deserialize, Serialize};
use serde_json::Value;
Expand Down Expand Up @@ -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<String, String>,
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 tup: String,
pub address: String,
pub port: i64,
}

#[derive(Debug)]
pub enum JsonRpc<N, R> {
Request(usize, R),
Expand Down

0 comments on commit 1c39564

Please sign in to comment.