Skip to content

Commit

Permalink
cln-plugin: Save "configuration" from "init" method
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmoon committed May 20, 2022
1 parent c7d359b commit 9c3f2c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,6 +45,7 @@ where

hooks: HashMap<String, Hook<S>>,
options: Vec<ConfigOption>,
configuration: Option<Configuration>,
rpcmethods: HashMap<String, RpcMethod<S>>,
subscriptions: HashMap<String, Subscription<S>>,
}
Expand All @@ -62,6 +64,7 @@ where
hooks: HashMap::new(),
subscriptions: HashMap::new(),
options: vec![],
configuration: None,
rpcmethods: HashMap::new(),
}
}
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -297,6 +301,8 @@ where
}
}

self.configuration = Some(call.configuration);

Ok(messages::InitResponse::default())
}
}
Expand Down Expand Up @@ -363,7 +369,7 @@ where
/// The state gets cloned for each request
state: S,
options: Vec<ConfigOption>,

configuration: Configuration,
/// A signal that allows us to wait on the plugin's shutdown.
wait_handle: tokio::sync::broadcast::Sender<()>,

Expand Down Expand Up @@ -635,6 +641,9 @@ where
pub fn options(&self) -> Vec<ConfigOption> {
self.options.clone()
}
pub fn configuration(&self) -> Configuration {
self.configuration.clone()
}
pub fn state(&self) -> &S {
&self.state
}
Expand All @@ -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::*;
Expand Down
2 changes: 2 additions & 0 deletions plugins/src/messages.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::options::ConfigOption;
use crate::Configuration;
use serde::de::{self, Deserializer};
use serde::{Deserialize, Serialize};
use serde_json::Value;
Expand Down Expand Up @@ -63,6 +64,7 @@ pub struct GetManifestCall {}
#[derive(Deserialize, Debug)]
pub(crate) struct InitCall {
pub(crate) options: HashMap<String, Value>,
pub(crate) configuration: Configuration,
}

#[derive(Debug)]
Expand Down

0 comments on commit 9c3f2c9

Please sign in to comment.