From f9a0786aceef2f9da7c41435c8de6ae264f211dd Mon Sep 17 00:00:00 2001 From: Peter Neuroth Date: Wed, 4 Sep 2024 11:35:35 +0200 Subject: [PATCH] gl-plugin: Return payment_hash as bytes directly Signed-off-by: Peter Neuroth --- libs/gl-client-py/tests/test_plugin.py | 1 + libs/gl-plugin/src/node/mod.rs | 31 ++++++++++++++------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/libs/gl-client-py/tests/test_plugin.py b/libs/gl-client-py/tests/test_plugin.py index 21d7cb2ee..5279e7d46 100644 --- a/libs/gl-client-py/tests/test_plugin.py +++ b/libs/gl-client-py/tests/test_plugin.py @@ -89,6 +89,7 @@ def test_trampoline_pay(bitcoind, clients, node_factory): res = n1.trampoline_pay(inv["bolt11"], bytes.fromhex(l2.info["id"])) assert res + assert len(res.payment_hash) == 32 # There was a confusion about hex/bytes retrun. l2.rpc.unsetchecks() diff --git a/libs/gl-plugin/src/node/mod.rs b/libs/gl-plugin/src/node/mod.rs index 9a6d4faf9..2a4cda6e3 100644 --- a/libs/gl-plugin/src/node/mod.rs +++ b/libs/gl-plugin/src/node/mod.rs @@ -395,11 +395,11 @@ impl Node for PluginNodeServer { ) -> Result, Status> { let req = request.into_inner(); - if req.error != "" { - log::error!("Signer reports an error: {}", req.error); - log::warn!("The above error was returned instead of a response."); - return Ok(Response::new(pb::Empty::default())); - } + if req.error != "" { + log::error!("Signer reports an error: {}", req.error); + log::warn!("The above error was returned instead of a response."); + return Ok(Response::new(pb::Empty::default())); + } // Create a state from the key-value-version tuples. Need to // convert here, since `pb` is duplicated in the two different @@ -566,18 +566,21 @@ impl Node for PluginNodeServer { &self, r: tonic::Request, ) -> Result, Status> { - match tramp::trampolinepay(r.into_inner(), self.rpc_path.clone()).await { + match tramp::trampolinepay(r.into_inner(), self.rpc_path.clone()) + .await + .map(|res| { + >::into( + res, + ) + }) { Ok(res) => Ok(tonic::Response::new(pb::TrampolinePayResponse { - payment_preimage: res.payment_preimage.to_vec(), - payment_hash: res.payment_hash.to_hex().into_bytes(), + payment_preimage: res.payment_preimage, + payment_hash: res.payment_hash, created_at: res.created_at, parts: res.parts, - amount_msat: res.amount_msat.msat(), - amount_sent_msat: res.amount_sent_msat.msat(), - destination: res - .destination - .map(|d| d.to_hex().into_bytes()) - .unwrap_or_default(), + amount_msat: res.amount_msat.unwrap_or_default().msat, + amount_sent_msat: res.amount_sent_msat.unwrap_or_default().msat, + destination: res.destination.unwrap_or_default(), })), Err(e) => Err(Status::new(Code::Unknown, e.to_string())), }