Crates.io | clightningrpc-plugin-macros |
lib.rs | clightningrpc-plugin-macros |
version | 0.3.0-beta.4 |
source | src |
created_at | 2022-07-29 23:24:51.875981 |
updated_at | 2023-06-13 09:44:04.15067 |
description | Crate that provides a procedural macros implementation to make easy to develop a plugin developer to build a plugin |
homepage | https://github.com/laanwj/rust-clightning-rpc |
repository | https://github.com/laanwj/rust-clightning-rpc.git |
max_upload_size | |
id | 635244 |
size | 33,563 |
Crate that provides a procedural macros implementation to make easy to develop a plugin developer to build a plugin.
Crate that provides a procedural macros implementation to make easy to develop a plugin developer to build a plugin.
use serde_json::json;
use serde_json::Value;
use clightningrpc_plugin_macros::*;
use clightningrpc_plugin::commands::RPCCommand;
use clightningrpc_plugin::errors::PluginError;
use clightningrpc_plugin::plugin::Plugin;
#[derive(Clone)]
struct State;
// FIXME: implement a derive macros to register
// the option plugins
impl State {
pub fn new() -> Self {
Self
}
}
#[rpc_method(
rpc_name = "foo_macro",
description = "This is a simple and short description"
)]
pub fn foo_rpc(plugin: &mut Plugin<State>, request: Value) -> Result<Value, PluginError> {
let response = json!({"is_dynamic": plugin.dynamic, "rpc_request": request});
Ok(response)
}
#[notification(on = "rpc_command")]
fn on_rpc(plugin: &mut Plugin<State>, request: &Value) {
use clightningrpc_plugin::types::LogLevel;
plugin.log(LogLevel::Info, "received an RPC notification");
}
fn main() {
let plugin = plugin! {
state: State::new(),
dynamic: true,
notification: [
on_rpc,
],
methods: [
foo_rpc,
],
hooks: [],
};
plugin.start();
}
make fmt
before committingIf you want support this library consider to donate with the following methods