Skip to content

Commit

Permalink
feat(plugin_macros): introduce error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Aug 27, 2022
1 parent 28f86d3 commit 0b9216f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions plugin_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ quote = "1.0"
darling = "0.14.1"
convert_case = "0.5.0"
serde_json = "1.0"
#clightningrpc-plugin = { path = "../plugin"}
clightningrpc-plugin = "0.3.0-beta.2"
clightningrpc-plugin = { path = "../plugin"}
#clightningrpc-plugin = "0.3.0-beta.2"

[dev-dependencies]
rstest = "0.10.0"
Expand Down
6 changes: 4 additions & 2 deletions plugin_macros/examples/macros_ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use clightningrpc_plugin_macros::{
use serde_json::{json, Value};

use clightningrpc_plugin::commands::RPCCommand;
use clightningrpc_plugin::errors::PluginError;
use clightningrpc_plugin::plugin::Plugin;
use clightningrpc_plugin::types::LogLevel;
use clightningrpc_plugin::{add_rpc, register_notification};
Expand All @@ -14,13 +15,14 @@ use clightningrpc_plugin::{add_rpc, register_notification};
rpc_name = "foo_macro",
description = "This is a simple and short description"
)]
pub fn foo_rpc(_plugin: Plugin<()>, _request: Value) -> Value {
pub fn foo_rpc(_plugin: Plugin<()>, _request: Value) -> Result<Value, PluginError> {
/// The name of the parameters can be used only if used, otherwise can be omitted
/// the only rules that the macros require is to have a propriety with the following rules:
/// - Plugin as _plugin
/// - CLN JSON request as _request
/// The function parameter can be specified in any order.
json!({"is_dynamic": _plugin.dynamic, "rpc_request": _request})
let response = json!({"is_dynamic": _plugin.dynamic, "rpc_request": _request});
Ok(response)
}

#[notification(on = "rpc_command")]
Expand Down
2 changes: 1 addition & 1 deletion plugin_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn generate_rpc_method(item: &TokenStream, method_call: &RPCCall) -> String {
impl<T: Clone + 'static> RPCCommand<T> for {}<T> {{
fn call<'c>(&self, _plugin: &mut Plugin<T>, _request: &'c Value) -> Value {{
fn call<'c>(&self, _plugin: &mut Plugin<T>, _request: &'c Value) -> Result<Value, PluginError> {{
{}
}}
}}
Expand Down

0 comments on commit 0b9216f

Please sign in to comment.