pub struct Builder<S, I, O>{ /* private fields */ }
Expand description
Builder for a new plugin.
Implementations§
Source§impl<S, I, O> Builder<S, I, O>
impl<S, I, O> Builder<S, I, O>
pub fn new(input: I, output: O) -> Self
pub fn option<'a, V: OptionType<'a>>( self, opt: ConfigOption<'a, V>, ) -> Builder<S, I, O>
pub fn notification(self, notif: NotificationTopic) -> Builder<S, I, O>
Sourcepub fn subscribe<C, F>(self, topic: &str, callback: C) -> Builder<S, I, O>
pub fn subscribe<C, F>(self, topic: &str, callback: C) -> Builder<S, I, O>
Subscribe to notifications for the given topic
. The handler
is an async function that takes a Plugin<S>
and the
notification as a serde_json::Value
as inputs. Since
notifications do not expect a result the handler should only
report errors while processing. Any error reported while
processing the notification will be logged in the cln logs.
use cln_plugin::{options, Builder, Error, Plugin};
async fn connect_handler(_p: Plugin<()>, v: serde_json::Value) -> Result<(), Error> {
println!("Got a connect notification: {}", v);
Ok(())
}
let b = Builder::new(tokio::io::stdin(), tokio::io::stdout())
.subscribe("connect", connect_handler);
Sourcepub fn hook<C, F>(self, hookname: &str, callback: C) -> Self
pub fn hook<C, F>(self, hookname: &str, callback: C) -> Self
Add a subscription to a given hookname
Sourcepub fn rpcmethod<C, F>(
self,
name: &str,
description: &str,
callback: C,
) -> Builder<S, I, O>
pub fn rpcmethod<C, F>( self, name: &str, description: &str, callback: C, ) -> Builder<S, I, O>
Register a custom RPC method for the RPC passthrough from the main daemon
pub fn rpcmethod_from_builder( self, rpc_method: RpcMethodBuilder<S>, ) -> Builder<S, I, O>
Sourcepub fn setconfig_callback<C, F>(self, setconfig_callback: C) -> Builder<S, I, O>
pub fn setconfig_callback<C, F>(self, setconfig_callback: C) -> Builder<S, I, O>
Register a callback for setconfig to accept changes for dynamic options
Sourcepub fn dynamic(self) -> Builder<S, I, O>
pub fn dynamic(self) -> Builder<S, I, O>
Send true value for “dynamic” field in “getmanifest” response
Sourcepub fn featurebits(self, kind: FeatureBitsKind, hex: String) -> Self
pub fn featurebits(self, kind: FeatureBitsKind, hex: String) -> Self
Sets the “featurebits” in the “getmanifest” response
Sourcepub fn with_logging(self, log: bool) -> Builder<S, I, O>
pub fn with_logging(self, log: bool) -> Builder<S, I, O>
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
that’ll interfere with the plugin communication. See the CLN
documentation on logging to see what logging events should
look like.
Sourcepub fn custommessages(self, custommessages: Vec<u16>) -> Self
pub fn custommessages(self, custommessages: Vec<u16>) -> Self
Tells lightningd explicitly to allow custommmessages of the provided type
Sourcepub async fn configure(self) -> Result<Option<ConfiguredPlugin<S, I, O>>, Error>
pub async fn configure(self) -> Result<Option<ConfiguredPlugin<S, I, O>>, Error>
Communicate with lightningd
to tell it about our options,
RPC methods and subscribe to hooks, and then process the
initialization, configuring the plugin.
Returns None
if we were invoked with --help
and thus
should exit after this handshake
Sourcepub async fn start(self, state: S) -> Result<Option<Plugin<S>>, Error>
pub async fn start(self, state: S) -> Result<Option<Plugin<S>>, Error>
Build and start the plugin loop. This performs the handshake and spawns a new task that accepts incoming messages from Core Lightning and dispatches them to the handlers. It only returns after completing the handshake to ensure that the configuration and initialization was successfull.
If lightningd
was called with --help
we won’t get a
Plugin
instance and return None
instead. This signals that
we should exit, and not continue running. start()
returns in
order to allow user code to perform cleanup if necessary.