diff --git a/plugins/lsps-plugin/src/core/transport.rs b/plugins/lsps-plugin/src/core/transport.rs index 5e5ce7496..0d86afbff 100644 --- a/plugins/lsps-plugin/src/core/transport.rs +++ b/plugins/lsps-plugin/src/core/transport.rs @@ -39,8 +39,9 @@ pub type Result = std::result::Result; /// request over some transport mechanism (RPC, Bolt8, etc.) #[async_trait] pub trait Transport: Send + Sync { - async fn send(&self, peer: &PublicKey, request: String) -> Result; - async fn notify(&self, peer: &PublicKey, request: String) -> Result<()>; + async fn send(&self, peer: &PublicKey, request: &str) -> Result; + async fn notify(&self, peer: &PublicKey, request: &str) -> Result<()>; +} } /// A typed JSON-RPC client that works with any transport implementation. @@ -152,7 +153,7 @@ impl JsonRpcClient { method, id, &request_json ); let start = tokio::time::Instant::now(); - let res_str = self.transport.send(peer, request_json).await?; + let res_str = self.transport.send(peer, &request_json).await?; let elapsed = start.elapsed(); debug!( "Received response: method={}, id={}, response={}, elapsed={}ms", @@ -176,7 +177,7 @@ impl JsonRpcClient { let request_json = serde_json::to_string(&payload)?; debug!("Sending notification: method={}", method); let start = tokio::time::Instant::now(); - self.transport.notify(peer_id, request_json).await?; + self.transport.notify(peer_id, &request_json).await?; let elapsed = start.elapsed(); debug!( "Sent notification: method={}, elapsed={}ms", @@ -241,10 +242,10 @@ mod test_json_rpc { async fn send( &self, _peer_id: &PublicKey, - req: String, + req: &str, ) -> core::result::Result { // Store the request - let _ = self.req.set(req); + let _ = self.req.set(req.to_owned()); // Check for error first if let Some(err) = &*self.err { @@ -259,13 +260,9 @@ mod test_json_rpc { panic!("TestTransport: neither result nor error is set."); } - async fn notify( - &self, - _peer_id: &PublicKey, - req: String, - ) -> core::result::Result<(), Error> { + async fn notify(&self, _peer_id: &PublicKey, req: &str) -> core::result::Result<(), Error> { // Store the request - let _ = self.req.set(req); + let _ = self.req.set(req.to_owned()); // Check for error if let Some(err) = &*self.err { diff --git a/plugins/lsps-plugin/src/lsps0/transport.rs b/plugins/lsps-plugin/src/lsps0/transport.rs index f549ccf88..ffc98e920 100644 --- a/plugins/lsps-plugin/src/lsps0/transport.rs +++ b/plugins/lsps-plugin/src/lsps0/transport.rs @@ -208,7 +208,7 @@ impl Bolt8Transport { &self, client: &mut ClnRpc, peer_id: &PublicKey, - payload: Vec, + payload: &[u8], ) -> Result<(), Error> { send_custommsg(client, payload, peer_id).await } @@ -228,12 +228,12 @@ impl Bolt8Transport { /// Sends a custom message to the destination node. pub async fn send_custommsg( client: &mut ClnRpc, - payload: Vec, + payload: &[u8], peer: &PublicKey, ) -> Result<(), Error> { let msg = CustomMsg { message_type: LSPS0_MESSAGE_TYPE, - payload, + payload: payload.to_owned(), }; let request = cln_rpc::model::requests::SendcustommsgRequest { @@ -257,9 +257,9 @@ impl Transport for Bolt8Transport { async fn send( &self, peer_id: &PublicKey, - request: String, + request: &str, ) -> core::result::Result { - let id = extract_message_id(&request)?; + let id = extract_message_id(request)?; let mut client = self.connect_to_node().await?; let (tx, rx) = mpsc::channel(1); @@ -274,7 +274,7 @@ impl Transport for Bolt8Transport { self.hook_watcher .subscribe_hook_once(id, Arc::downgrade(&tx_arc)) .await; - self.send_custom_msg(&mut client, peer_id, request.into_bytes()) + self.send_custom_msg(&mut client, peer_id, request.as_bytes()) .await?; let res = self.wait_for_response(rx).await?; @@ -297,13 +297,9 @@ impl Transport for Bolt8Transport { } /// Sends a notification without waiting for a response. - async fn notify( - &self, - peer_id: &PublicKey, - request: String, - ) -> core::result::Result<(), Error> { + async fn notify(&self, peer_id: &PublicKey, request: &str) -> core::result::Result<(), Error> { let mut client = self.connect_to_node().await?; - self.send_custom_msg(&mut client, peer_id, request.into_bytes()) + self.send_custom_msg(&mut client, peer_id, request.as_bytes()) .await } } diff --git a/plugins/lsps-plugin/src/service.rs b/plugins/lsps-plugin/src/service.rs index 2b4430453..ea0def450 100644 --- a/plugins/lsps-plugin/src/service.rs +++ b/plugins/lsps-plugin/src/service.rs @@ -189,6 +189,6 @@ impl JsonRpcResponseWriter for LspsResponseWriter { let mut client = cln_rpc::ClnRpc::new(&self.rpc_path) .await .map_err(|e| Error::Internal(e.to_string()))?; - transport::send_custommsg(&mut client, payload.to_vec(), &self.peer_id).await + transport::send_custommsg(&mut client, payload, &self.peer_id).await } }