mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
cln-plugin: Save "configuration" from "init" method
This commit is contained in:
committed by
Christian Decker
parent
9a880a0932
commit
14483901cd
@@ -3,6 +3,7 @@ pub use anyhow::{anyhow, Context};
|
|||||||
use futures::sink::SinkExt;
|
use futures::sink::SinkExt;
|
||||||
extern crate log;
|
extern crate log;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
use serde::Deserialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
@@ -44,6 +45,7 @@ where
|
|||||||
|
|
||||||
hooks: HashMap<String, Hook<S>>,
|
hooks: HashMap<String, Hook<S>>,
|
||||||
options: Vec<ConfigOption>,
|
options: Vec<ConfigOption>,
|
||||||
|
configuration: Option<Configuration>,
|
||||||
rpcmethods: HashMap<String, RpcMethod<S>>,
|
rpcmethods: HashMap<String, RpcMethod<S>>,
|
||||||
subscriptions: HashMap<String, Subscription<S>>,
|
subscriptions: HashMap<String, Subscription<S>>,
|
||||||
}
|
}
|
||||||
@@ -62,6 +64,7 @@ where
|
|||||||
hooks: HashMap::new(),
|
hooks: HashMap::new(),
|
||||||
subscriptions: HashMap::new(),
|
subscriptions: HashMap::new(),
|
||||||
options: vec![],
|
options: vec![],
|
||||||
|
configuration: None,
|
||||||
rpcmethods: HashMap::new(),
|
rpcmethods: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,6 +210,7 @@ where
|
|||||||
let plugin = Plugin {
|
let plugin = Plugin {
|
||||||
state: self.state,
|
state: self.state,
|
||||||
options: self.options,
|
options: self.options,
|
||||||
|
configuration: self.configuration.unwrap(), // OK to unwrap, set in handle_init
|
||||||
wait_handle,
|
wait_handle,
|
||||||
sender,
|
sender,
|
||||||
};
|
};
|
||||||
@@ -297,6 +301,8 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.configuration = Some(call.configuration);
|
||||||
|
|
||||||
Ok(messages::InitResponse::default())
|
Ok(messages::InitResponse::default())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -363,7 +369,7 @@ where
|
|||||||
/// The state gets cloned for each request
|
/// The state gets cloned for each request
|
||||||
state: S,
|
state: S,
|
||||||
options: Vec<ConfigOption>,
|
options: Vec<ConfigOption>,
|
||||||
|
configuration: Configuration,
|
||||||
/// A signal that allows us to wait on the plugin's shutdown.
|
/// A signal that allows us to wait on the plugin's shutdown.
|
||||||
wait_handle: tokio::sync::broadcast::Sender<()>,
|
wait_handle: tokio::sync::broadcast::Sender<()>,
|
||||||
|
|
||||||
@@ -635,6 +641,9 @@ where
|
|||||||
pub fn options(&self) -> Vec<ConfigOption> {
|
pub fn options(&self) -> Vec<ConfigOption> {
|
||||||
self.options.clone()
|
self.options.clone()
|
||||||
}
|
}
|
||||||
|
pub fn configuration(&self) -> Configuration {
|
||||||
|
self.configuration.clone()
|
||||||
|
}
|
||||||
pub fn state(&self) -> &S {
|
pub fn state(&self) -> &S {
|
||||||
&self.state
|
&self.state
|
||||||
}
|
}
|
||||||
@@ -653,6 +662,12 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
|
pub struct Configuration {
|
||||||
|
#[serde(rename = "lightning-dir")]
|
||||||
|
pub lightning_dir: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::options::ConfigOption;
|
use crate::options::ConfigOption;
|
||||||
|
use crate::Configuration;
|
||||||
use serde::de::{self, Deserializer};
|
use serde::de::{self, Deserializer};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
@@ -63,6 +64,7 @@ pub struct GetManifestCall {}
|
|||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub(crate) struct InitCall {
|
pub(crate) struct InitCall {
|
||||||
pub(crate) options: HashMap<String, Value>,
|
pub(crate) options: HashMap<String, Value>,
|
||||||
|
pub(crate) configuration: Configuration,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
Reference in New Issue
Block a user