#plugin #plugin-api #lightning #bitcoin #cln #rpc

clightningrpc-plugin

Crate that provides a plugin API to give the possibility to implement a plugin in Rust

8 releases

0.3.0-beta.8 Jun 13, 2023
0.3.0-beta.7 Jan 7, 2023
0.3.0-beta.6 Nov 18, 2022
0.3.0-beta.5 Sep 3, 2022
0.1.0-beta.1 Jul 29, 2022

#5 in #cln

Download history 131/week @ 2024-04-07 84/week @ 2024-04-14 8/week @ 2024-04-21 15/week @ 2024-04-28 68/week @ 2024-05-05 25/week @ 2024-05-12 15/week @ 2024-05-19 6/week @ 2024-05-26 38/week @ 2024-06-02 18/week @ 2024-06-09 1/week @ 2024-06-16 17/week @ 2024-06-23 23/week @ 2024-06-30 23/week @ 2024-07-07 2/week @ 2024-07-14 39/week @ 2024-07-21

88 downloads per month
Used in clightningrpc-plugin-macr…

CC0 license

39KB
685 lines

Rust core lightning plugin crate

Crate that provides a procedural API to develop cln plugins.

Project Homepage

GitHub Workflow Status (branch) Crates.io docs.rs

Crate that provides a procedural macros implementation to make easy to develop a plugin developer to build a plugin.

extern crate clightningrpc_plugin;

use clightningrpc_plugin::types::LogLevel;
use clightningrpc_plugin::{commands::RPCCommand, plugin::Plugin};
use serde_json::{json, Value};

#[derive(Clone)]
struct PluginState(());

/// HelloRPC is used to register the RPC method
#[derive(Clone)]
struct HelloRPC {}

/// Implementation of the RPC method
impl RPCCommand<PluginState> for HelloRPC {
    fn call<'c>(&self, plugin: &mut Plugin<PluginState>, _request: &'c Value) -> Value {
        plugin.log(LogLevel::Debug, "call the custom rpc method from rust");
        json!({
            "language": "Hello from rust"
        })
    }
}

#[derive(Clone)]
struct OnChannelOpened {}

impl RPCCommand<PluginState> for OnChannelOpened {
    fn call_void<'c>(&self, _plugin: &mut Plugin<PluginState>, _request: &'c Value) {
        _plugin.log(LogLevel::Debug, "A new channel was opened!");
    }
}

fn main() {
    let mut plugin = Plugin::<PluginState>::new(PluginState(()), true)
        .add_rpc_method(
            "hello",
            "",
            "show how is possible add a method",
            HelloRPC {},
        )
        .add_opt(
            "foo",
            "flag",
            None,
            "An example of command line option",
            false,
        )
        .register_notification("channel_opened", OnChannelOpened {})
        .clone();
    plugin.start();
}

Contributing guidelines

Read our Hacking guide

Supports

If you want support this library consider to donate with the following methods

Dependencies

~0.7–1.7MB
~36K SLoC