cln-plugin: Save "configuration" from "init" method

This commit is contained in:
Justin Moon
2022-05-20 16:20:24 -05:00
committed by Christian Decker
parent 9a880a0932
commit 14483901cd
2 changed files with 18 additions and 1 deletions

View File

@@ -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<String, Hook<S>>,
options: Vec<ConfigOption>,
configuration: Option<Configuration>,
rpcmethods: HashMap<String, RpcMethod<S>>,
subscriptions: HashMap<String, Subscription<S>>,
}
@@ -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<ConfigOption>,
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<ConfigOption> {
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::*;

View File

@@ -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<String, Value>,
pub(crate) configuration: Configuration,
}
#[derive(Debug)]