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

clightningrpc-plugin

提供插件API的crate,允许在Rust中实现插件

8个版本

0.3.0-beta.82023年6月13日
0.3.0-beta.72023年1月7日
0.3.0-beta.62022年11月18日
0.3.0-beta.52022年9月3日
0.1.0-beta.12022年7月29日

5#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次 下载
用于 clightningrpc-plugin-macr…

CC0 许可证

39KB
685

Rust核心lightning插件crate

提供过程式API以开发cln插件的crate。

项目主页

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

提供过程式宏实现,简化插件开发。

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();
}

贡献指南

阅读我们的黑客指南

支持

如果您想支持这个库,请考虑以下方式捐赠:

依赖项

~0.7–1.7MB
~36K SLoC