Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin): fix nop operation while handling notification #129

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions plugin/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::collections::{HashMap, HashSet};
use std::io;
use std::io::Write;
use std::string::String;

Check warning on line 7 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

the item `String` is imported redundantly

Check warning on line 7 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

the item `String` is imported redundantly

Check warning on line 7 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `String` is imported redundantly

Check warning on line 7 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `String` is imported redundantly

Check warning on line 7 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `String` is imported redundantly

Check warning on line 7 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `String` is imported redundantly

Check warning on line 7 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

the item `String` is imported redundantly

Check warning on line 7 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / Build (beta)

the item `String` is imported redundantly
use std::sync::Arc;

use clightningrpc_common::json_utils::{add_str, init_payload, init_success_response};
Expand Down Expand Up @@ -50,7 +50,7 @@
/// core lightning configuration sent with the init call.
pub configuration: Option<CLNConf>,
/// onInit callback called when the method on init is ran.
on_init: Option<Arc<dyn Fn(&mut Plugin<T>) -> Value>>,

Check warning on line 53 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> plugin/src/plugin.rs:53:14 | 53 | on_init: Option<Arc<dyn Fn(&mut Plugin<T>) -> Value>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity
}

#[cfg(feature = "log")]
Expand Down Expand Up @@ -139,10 +139,10 @@
) -> &mut Self {
let def_val = match opt_type {
"flag" | "bool" => {
def_val.and_then(|val| Some(serde_json::json!(val.parse::<bool>().unwrap())))

Check warning on line 142 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`

warning: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` --> plugin/src/plugin.rs:142:17 | 142 | def_val.and_then(|val| Some(serde_json::json!(val.parse::<bool>().unwrap()))) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `def_val.map(|val| serde_json::json!(val.parse::<bool>().unwrap()))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map = note: `#[warn(clippy::bind_instead_of_map)]` on by default
}
"int" => def_val.and_then(|val| Some(serde_json::json!(val.parse::<i64>().unwrap()))),

Check warning on line 144 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`

warning: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` --> plugin/src/plugin.rs:144:22 | 144 | "int" => def_val.and_then(|val| Some(serde_json::json!(val.parse::<i64>().unwrap()))), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `def_val.map(|val| serde_json::json!(val.parse::<i64>().unwrap()))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map
"string" => def_val.and_then(|val| Some(serde_json::json!(val))),

Check warning on line 145 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`

warning: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` --> plugin/src/plugin.rs:145:25 | 145 | "string" => def_val.and_then(|val| Some(serde_json::json!(val))), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `def_val.map(|val| serde_json::json!(val))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bind_instead_of_map
_ => unreachable!("{opt_type} not supported"),
};
self.option.insert(
Expand Down Expand Up @@ -210,12 +210,7 @@

fn handle_notification(&'a mut self, name: &str, params: serde_json::Value) {
let notification = self.rpc_notification.get(name).unwrap().clone();
if let Err(json_res) = notification.call(self, params) {
self.log(
LogLevel::Debug,
format!("Notification end with and error: {json_res}").as_str(),
);
}
notification.call_void(self, &params);
}

pub fn register_hook<F: 'static>(
Expand Down Expand Up @@ -284,7 +279,7 @@
// FIXME: core lightning end with the double endline, so this can cause
// problem for some input reader.
// we need to parse the writer, and avoid this while loop
while let Ok(_) = reader.read_line(&mut buffer) {

Check warning on line 282 in plugin/src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant pattern matching, consider using `is_ok()`

warning: redundant pattern matching, consider using `is_ok()` --> plugin/src/plugin.rs:282:19 | 282 | while let Ok(_) = reader.read_line(&mut buffer) { | ----------^^^^^-------------------------------- help: try: `while reader.read_line(&mut buffer).is_ok()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching = note: `#[warn(clippy::redundant_pattern_matching)]` on by default
let req_str = buffer.to_string();
buffer.clear();
let Ok(request) = serde_json::from_str::<Request<serde_json::Value>>(&req_str) else {
Expand Down
Loading