mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
cln-plugin: Allow user to set featurebits
This commit is contained in:
parent
a38d81dee0
commit
870e25e180
2 changed files with 47 additions and 1 deletions
|
@ -5,7 +5,7 @@ use futures::sink::SinkExt;
|
|||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
extern crate log;
|
||||
use log::trace;
|
||||
use messages::{Configuration, NotificationTopic};
|
||||
use messages::{Configuration, NotificationTopic, FeatureBits};
|
||||
use options::ConfigOption;
|
||||
use std::collections::HashMap;
|
||||
use std::future::Future;
|
||||
|
@ -48,6 +48,7 @@ where
|
|||
subscriptions: HashMap<String, Subscription<S>>,
|
||||
notifications: Vec<NotificationTopic>,
|
||||
custommessages : Vec<u16>,
|
||||
featurebits: FeatureBits,
|
||||
dynamic: bool,
|
||||
// Do we want the plugin framework to automatically register a logging handler?
|
||||
logging: bool,
|
||||
|
@ -122,6 +123,7 @@ where
|
|||
options: vec![],
|
||||
rpcmethods: HashMap::new(),
|
||||
notifications: vec![],
|
||||
featurebits: FeatureBits::default(),
|
||||
dynamic: false,
|
||||
custommessages : vec![],
|
||||
logging: true,
|
||||
|
@ -219,6 +221,17 @@ where
|
|||
self
|
||||
}
|
||||
|
||||
/// Sets the "featurebits" in the "getmanifest" response
|
||||
pub fn featurebits(mut self, place: FeatureBitsPlace, hex: String) -> Self {
|
||||
match place {
|
||||
FeatureBitsPlace::Node => self.featurebits.node = Some(hex),
|
||||
FeatureBitsPlace::Channel => self.featurebits.channel = Some(hex),
|
||||
FeatureBitsPlace::Init => self.featurebits.init = Some(hex),
|
||||
FeatureBitsPlace::Invoice => self.featurebits.invoice = Some(hex),
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Should the plugin automatically register a logging handler? If
|
||||
/// not you may need to register a logging handler yourself. Be
|
||||
/// careful not to print raw lines to `stdout` if you do, since
|
||||
|
@ -361,6 +374,7 @@ where
|
|||
hooks: self.hooks.keys().map(|s| s.clone()).collect(),
|
||||
rpcmethods,
|
||||
notifications: self.notifications.clone(),
|
||||
featurebits: self.featurebits.clone(),
|
||||
dynamic: self.dynamic,
|
||||
nonnumericids: true,
|
||||
custommessages : self.custommessages.clone()
|
||||
|
@ -773,3 +787,22 @@ where
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub enum FeatureBitsPlace {
|
||||
Node,
|
||||
Channel,
|
||||
Invoice,
|
||||
Init,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn init() {
|
||||
let state = ();
|
||||
let builder = Builder::new(tokio::io::stdin(), tokio::io::stdout());
|
||||
let _ = builder.start(state);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,11 +177,24 @@ pub(crate) struct GetManifestResponse {
|
|||
pub(crate) notifications: Vec<NotificationTopic>,
|
||||
pub(crate) hooks: Vec<String>,
|
||||
pub(crate) dynamic: bool,
|
||||
pub(crate) featurebits: FeatureBits,
|
||||
pub(crate) nonnumericids: bool,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub(crate) custommessages : Vec<u16>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Default, Debug, Clone)]
|
||||
pub(crate) struct FeatureBits {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub node: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub channel: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub init: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub invoice: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Default, Debug)]
|
||||
pub struct InitResponse {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
|
Loading…
Add table
Reference in a new issue