Skip to content

Commit

Permalink
gl-plugin: Return payment_hash as bytes directly
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Neuroth <[email protected]>
  • Loading branch information
nepet authored and cdecker committed Sep 4, 2024
1 parent 8e33b8c commit 7540980
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
1 change: 1 addition & 0 deletions libs/gl-client-py/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 return.

l2.rpc.unsetchecks()

Expand Down
31 changes: 17 additions & 14 deletions libs/gl-plugin/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ impl Node for PluginNodeServer {
) -> Result<Response<pb::Empty>, 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
Expand Down Expand Up @@ -566,18 +566,21 @@ impl Node for PluginNodeServer {
&self,
r: tonic::Request<pb::TrampolinePayRequest>,
) -> Result<tonic::Response<pb::TrampolinePayResponse>, 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| {
<cln_rpc::model::responses::PayResponse as Into<cln_grpc::pb::PayResponse>>::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())),
}
Expand Down

0 comments on commit 7540980

Please sign in to comment.