Struct cln_plugin::Builder
source · [−]pub struct Builder<S, I, O> where
I: AsyncRead + Unpin,
O: Send + AsyncWrite + Unpin,
S: Clone + Send, { /* private fields */ }Expand description
Builder for a new plugin.
Implementations
sourceimpl<S, I, O> Builder<S, I, O> where
O: Send + AsyncWrite + Unpin + 'static,
S: Clone + Sync + Send + 'static,
I: AsyncRead + Send + Unpin + 'static,
impl<S, I, O> Builder<S, I, O> where
O: Send + AsyncWrite + Unpin + 'static,
S: Clone + Sync + Send + 'static,
I: AsyncRead + Send + Unpin + 'static,
pub fn new(state: S, input: I, output: O) -> Self
pub fn option(self, opt: ConfigOption) -> Builder<S, I, O>
sourcepub fn subscribe<C, F>(self, topic: &str, callback: C) -> Builder<S, I, O> where
C: Send + Sync + 'static,
C: Fn(Plugin<S>, Value) -> F + 'static,
F: Future<Output = Result<(), Error>> + Send + Sync + 'static,
pub fn subscribe<C, F>(self, topic: &str, callback: C) -> Builder<S, I, O> where
C: Send + Sync + 'static,
C: Fn(Plugin<S>, Value) -> F + 'static,
F: Future<Output = Result<(), Error>> + Send + Sync + 'static,
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 where
C: Send + Sync + 'static,
C: Fn(Plugin<S>, Value) -> F + 'static,
F: Future<Output = Result<Value, Error>> + Send + Sync + 'static,
pub fn hook<C, F>(self, hookname: &str, callback: C) -> Self where
C: Send + Sync + 'static,
C: Fn(Plugin<S>, Value) -> F + 'static,
F: Future<Output = Result<Value, Error>> + Send + Sync + 'static,
Add a subscription to a given hookname
sourcepub fn rpcmethod<C, F>(
self,
name: &str,
description: &str,
callback: C
) -> Builder<S, I, O> where
C: Send + Sync + 'static,
C: Fn(Plugin<S>, Value) -> F + 'static,
F: Future<Output = Result<Value, Error>> + Send + Sync + 'static,
pub fn rpcmethod<C, F>(
self,
name: &str,
description: &str,
callback: C
) -> Builder<S, I, O> where
C: Send + Sync + 'static,
C: Fn(Plugin<S>, Value) -> F + 'static,
F: Future<Output = Result<Value, Error>> + Send + Sync + 'static,
Register a custom RPC method for the RPC passthrough from the main daemon
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) -> Result<Option<Plugin<S>>, Error>
pub async fn start(self) -> 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.
Auto Trait Implementations
impl<S, I, O> !RefUnwindSafe for Builder<S, I, O>
impl<S, I, O> Send for Builder<S, I, O> where
I: Send,
impl<S, I, O> Sync for Builder<S, I, O> where
I: Sync,
O: Sync,
S: Sync,
impl<S, I, O> Unpin for Builder<S, I, O> where
S: Unpin,
impl<S, I, O> !UnwindSafe for Builder<S, I, O>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more