Crates.io | clightningrpc-plugin |
lib.rs | clightningrpc-plugin |
version | 0.3.0-beta.8 |
source | src |
created_at | 2022-07-29 23:23:02.542093 |
updated_at | 2023-06-13 09:32:56.194417 |
description | Crate that provides a plugin API to give the possibility to implement a plugin in Rust |
homepage | https://github.com/laanwj/rust-clightning-rpc |
repository | https://github.com/laanwj/rust-clightning-rpc.git |
max_upload_size | |
id | 635243 |
size | 33,868 |
Crate that provides a procedural API to develop cln plugins.
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();
}
Read our Hacking guide
If you want support this library consider to donate with the following methods