Skip to content

Commit

Permalink
cln-plugin: Allow user to set featurebits
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikDeSmedt committed Jan 12, 2024
1 parent 000fceb commit b222a74
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
23 changes: 22 additions & 1 deletion plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,6 +47,7 @@ where
rpcmethods: HashMap<String, RpcMethod<S>>,
subscriptions: HashMap<String, Subscription<S>>,
notifications: Vec<NotificationTopic>,
featurebits: FeatureBits,
dynamic: bool,
// Do we want the plugin framework to automatically register a logging handler?
logging: bool,
Expand Down Expand Up @@ -121,6 +122,7 @@ where
options: vec![],
rpcmethods: HashMap::new(),
notifications: vec![],
featurebits: FeatureBits::default(),
dynamic: false,
logging: true,
}
Expand Down Expand Up @@ -210,6 +212,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
Expand Down Expand Up @@ -345,6 +358,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,
}
Expand Down Expand Up @@ -708,6 +722,13 @@ where
}
}

pub enum FeatureBitsPlace {
Node,
Channel,
Invoice,
Init,
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
13 changes: 13 additions & 0 deletions plugins/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,22 @@ 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,
}

#[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")]
Expand Down

0 comments on commit b222a74

Please sign in to comment.