Skip to content

Commit 7f5ffb4

Browse files
committed
renepay: use injectpaymentonion
Use injectpaymentonion for payments with |routes|=0, ie. self-payments and blinded paths where our node is the first node in the blinded path. Changelog-None. Signed-off-by: Lagrang3 <[email protected]>
1 parent 45ac11c commit 7f5ffb4

File tree

1 file changed

+49
-21
lines changed

1 file changed

+49
-21
lines changed

plugins/renepay/sendpay.c

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,13 @@ static struct command_result *renesendpay_done(struct command *cmd,
342342
return command_finished(cmd, response);
343343
}
344344

345+
static u32 initial_cltv_delta(const struct renesendpay *renesendpay)
346+
{
347+
if (tal_count(renesendpay->route) == 0)
348+
return renesendpay->final_cltv;
349+
return renesendpay->route[0].delay;
350+
}
351+
345352
static struct command_result *waitblockheight_done(struct command *cmd,
346353
const char *method UNUSED,
347354
const char *buffer,
@@ -389,31 +396,52 @@ static struct command_result *waitblockheight_done(struct command *cmd,
389396

390397
json_add_node_id(req->js, "destination",
391398
&renesendpay->destination);
392-
399+
json_add_sha256(req->js, "payment_hash",
400+
&renesendpay->payment_hash);
401+
json_add_u64(req->js, "partid", renesendpay->partid);
402+
json_add_u64(req->js, "groupid", renesendpay->groupid);
403+
if (renesendpay->label)
404+
json_add_string(req->js, "label", renesendpay->label);
405+
if (renesendpay->description)
406+
json_add_string(req->js, "description",
407+
renesendpay->description);
408+
if (renesendpay->invoice)
409+
json_add_string(req->js, "bolt11",
410+
renesendpay->invoice);
393411
} else {
394-
/* self payment */
395-
onion = NULL;
396-
req = jsonrpc_request_start(cmd, "sendpay", renesendpay_done,
397-
rpc_fail, renesendpay);
398-
json_array_start(req->js, "route");
399-
json_array_end(req->js);
412+
/* This is either a self-payment or a payment through a blinded
413+
* path that starts at our node. */
414+
// FIXME: do this with injectpaymentonion.
415+
// FIXME: we could make all payments with injectpaymentonion but
416+
// we need to make sure first that we don't lose older features,
417+
// like for example to be able to show in listsendpays the
418+
// recepient of the payment.
419+
onion = create_onion(tmpctx, renesendpay, pay_plugin->my_id, 0);
420+
req = jsonrpc_request_start(cmd, "injectpaymentonion",
421+
renesendpay_done, rpc_fail,
422+
renesendpay);
423+
424+
json_add_hex_talarr(req->js, "onion", onion);
425+
json_add_sha256(req->js, "payment_hash",
426+
&renesendpay->payment_hash);
427+
json_add_u64(req->js, "partid", renesendpay->partid);
428+
json_add_u64(req->js, "groupid", renesendpay->groupid);
429+
if (renesendpay->label)
430+
json_add_string(req->js, "label", renesendpay->label);
431+
if (renesendpay->invoice)
432+
json_add_string(req->js, "invstring",
433+
renesendpay->invoice);
400434
json_add_amount_msat(req->js, "amount_msat",
401-
renesendpay->total_amount);
402-
if(renesendpay->payment_secret)
403-
json_add_secret(req->js, "payment_secret", renesendpay->payment_secret);
435+
renesendpay->sent_amount);
436+
json_add_amount_msat(req->js, "destination_msat",
437+
renesendpay->deliver_amount);
438+
json_add_amount_msat(req->js, "destination_msat",
439+
renesendpay->deliver_amount);
440+
json_add_u32(req->js, "cltv_expiry",
441+
initial_cltv_delta(renesendpay) +
442+
renesendpay->blockheight);
404443
}
405444

406-
json_add_sha256(req->js, "payment_hash", &renesendpay->payment_hash);
407-
json_add_u64(req->js, "partid", renesendpay->partid);
408-
json_add_u64(req->js, "groupid", renesendpay->groupid);
409-
if (renesendpay->label)
410-
json_add_string(req->js, "label", renesendpay->label);
411-
if (renesendpay->description)
412-
json_add_string(req->js, "description",
413-
renesendpay->description);
414-
if (renesendpay->invoice)
415-
json_add_string(req->js, "bolt11", renesendpay->invoice);
416-
417445
return send_outreq(req);
418446
}
419447

0 commit comments

Comments
 (0)