cln_plugin

Struct 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§

Source§

impl<S, I, O> Builder<S, I, O>
where O: Send + AsyncWrite + Unpin + 'static, S: Clone + Sync + Send + 'static, I: AsyncRead + Send + Unpin + 'static,

Source

pub fn new(input: I, output: O) -> Self

Source

pub fn option<'a, V: OptionType<'a>>( self, opt: ConfigOption<'a, V>, ) -> Builder<S, I, O>

Source

pub fn notification(self, notif: NotificationTopic) -> Builder<S, I, O>

Source

pub fn subscribe<C, F>(self, topic: &str, callback: C) -> Builder<S, I, O>
where C: Send + Sync + 'static + Fn(Plugin<S>, Value) -> F, F: Future<Output = Result<(), Error>> + Send + '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);
Source

pub fn hook<C, F>(self, hookname: &str, callback: C) -> Self
where C: Send + Sync + 'static + Fn(Plugin<S>, Value) -> F, F: Future<Output = Result<Value, Error>> + Send + 'static,

Add a subscription to a given hookname

Source

pub fn rpcmethod<C, F>( self, name: &str, description: &str, callback: C, ) -> Builder<S, I, O>
where C: Send + Sync + 'static + Fn(Plugin<S>, Value) -> F, F: Future<Output = Result<Value, Error>> + Send + 'static,

Register a custom RPC method for the RPC passthrough from the main daemon

Source

pub fn rpcmethod_from_builder( self, rpc_method: RpcMethodBuilder<S>, ) -> Builder<S, I, O>

Source

pub fn setconfig_callback<C, F>(self, setconfig_callback: C) -> Builder<S, I, O>
where C: Send + Sync + 'static + Fn(Plugin<S>, Value) -> F, F: Future<Output = Result<Value, Error>> + Send + 'static,

Register a callback for setconfig to accept changes for dynamic options

Source

pub fn dynamic(self) -> Builder<S, I, O>

Send true value for “dynamic” field in “getmanifest” response

Source

pub fn featurebits(self, kind: FeatureBitsKind, hex: String) -> Self

Sets the “featurebits” in the “getmanifest” response

Source

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.

Source

pub fn custommessages(self, custommessages: Vec<u16>) -> Self

Tells lightningd explicitly to allow custommmessages of the provided type

Source

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

Source

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.

Auto Trait Implementations§

§

impl<S, I, O> Freeze for Builder<S, I, O>
where I: Freeze, O: Freeze,

§

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,

§

impl<S, I, O> Unpin for Builder<S, I, O>

§

impl<S, I, O> !UnwindSafe for Builder<S, I, O>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more