From 9c3f2c91c80a992fe6e4654280adea094741c1cd Mon Sep 17 00:00:00 2001 From: Justin Moon Date: Fri, 20 May 2022 16:20:24 -0500 Subject: [PATCH] cln-plugin: Save "configuration" from "init" method --- plugins/src/lib.rs | 17 ++++++++++++++++- plugins/src/messages.rs | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/plugins/src/lib.rs b/plugins/src/lib.rs index e91bb69f6e28..1e576f48dba3 100644 --- a/plugins/src/lib.rs +++ b/plugins/src/lib.rs @@ -3,6 +3,7 @@ pub use anyhow::{anyhow, Context}; use futures::sink::SinkExt; extern crate log; use log::trace; +use serde::Deserialize; use std::collections::HashMap; use std::future::Future; use std::pin::Pin; @@ -44,6 +45,7 @@ where hooks: HashMap>, options: Vec, + configuration: Option, rpcmethods: HashMap>, subscriptions: HashMap>, } @@ -62,6 +64,7 @@ where hooks: HashMap::new(), subscriptions: HashMap::new(), options: vec![], + configuration: None, rpcmethods: HashMap::new(), } } @@ -207,6 +210,7 @@ where let plugin = Plugin { state: self.state, options: self.options, + configuration: self.configuration.unwrap(), // OK to unwrap, set in handle_init wait_handle, sender, }; @@ -297,6 +301,8 @@ where } } + self.configuration = Some(call.configuration); + Ok(messages::InitResponse::default()) } } @@ -363,7 +369,7 @@ where /// The state gets cloned for each request state: S, options: Vec, - + configuration: Configuration, /// A signal that allows us to wait on the plugin's shutdown. wait_handle: tokio::sync::broadcast::Sender<()>, @@ -635,6 +641,9 @@ where pub fn options(&self) -> Vec { self.options.clone() } + pub fn configuration(&self) -> Configuration { + self.configuration.clone() + } pub fn state(&self) -> &S { &self.state } @@ -653,6 +662,12 @@ 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 4f19aaea9507..fb0642747b8e 100644 --- a/plugins/src/messages.rs +++ b/plugins/src/messages.rs @@ -1,4 +1,5 @@ use crate::options::ConfigOption; +use crate::Configuration; use serde::de::{self, Deserializer}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -63,6 +64,7 @@ pub struct GetManifestCall {} #[derive(Deserialize, Debug)] pub(crate) struct InitCall { pub(crate) options: HashMap, + pub(crate) configuration: Configuration, } #[derive(Debug)]