From d1c816660c0583db33d160e2ef3e980bef0d5a85 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Mon, 27 May 2024 00:59:23 +0200 Subject: p2p: WIP rpc server implementation for the p2p monitor --- jsonrpc/src/server/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'jsonrpc/src/server') diff --git a/jsonrpc/src/server/mod.rs b/jsonrpc/src/server/mod.rs index 7e9e969..e1805e1 100644 --- a/jsonrpc/src/server/mod.rs +++ b/jsonrpc/src/server/mod.rs @@ -4,7 +4,7 @@ pub mod service; use std::{collections::HashMap, sync::Arc}; -use log::{debug, error, warn}; +use log::{debug, error, trace, warn}; #[cfg(feature = "smol")] use futures_rustls::rustls; @@ -212,6 +212,7 @@ impl Server { channel: ArcChannel, msg: serde_json::Value, ) { + trace!("--> new request {msg}"); let on_failure = |result: TaskResult>| async move { if let TaskResult::Completed(Err(err)) = result { error!("Failed to handle a request: {err}"); @@ -250,7 +251,8 @@ impl Server { if let Some(service) = self.pubsub_services.get(&req.srvc_name) { if let Some(method) = service.get_pubsub_method(&req.method_name) { let name = format!("{}.{}", service.name(), req.method_name); - response.result = match method(channel, name, req.msg.params.clone()).await { + let params = req.msg.params.unwrap_or(serde_json::json!(())); + response.result = match method(channel, name, params).await { Ok(res) => Some(res), Err(err) => return self.handle_error(err, req.msg.id), }; @@ -261,7 +263,8 @@ impl Server { if let Some(service) = self.services.get(&req.srvc_name) { if let Some(method) = service.get_method(&req.method_name) { - response.result = match method(req.msg.params.clone()).await { + let params = req.msg.params.unwrap_or(serde_json::json!(())); + response.result = match method(params).await { Ok(res) => Some(res), Err(err) => return self.handle_error(err, req.msg.id), }; -- cgit v1.2.3