Skip to content

Commit 5668dfc

Browse files
committed
renepay: use our own sendpay rpc
Use renesendpay to send the payment allowing to pay to BOLT12 invoices from a higher level interface. Changelog-Add: renepay: Add support for BOLT12 payments Signed-off-by: Lagrang3 <[email protected]>
1 parent f0fad43 commit 5668dfc

File tree

1 file changed

+65
-6
lines changed

1 file changed

+65
-6
lines changed

plugins/renepay/routetracker.c

+65-6
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,73 @@ struct command_result *route_sendpay_request(struct command *cmd,
330330
struct route *route TAKES,
331331
struct payment *payment)
332332
{
333-
struct out_req *req =
334-
jsonrpc_request_start(cmd, "sendpay",
335-
sendpay_done, sendpay_failed, route);
336-
337-
json_add_route(req->js, route, payment);
333+
const struct payment_info *pinfo = &payment->payment_info;
334+
struct out_req *req = jsonrpc_request_start(
335+
cmd, "renesendpay", sendpay_done, sendpay_failed, route);
336+
337+
const size_t pathlen = tal_count(route->hops);
338+
json_add_sha256(req->js, "payment_hash", &pinfo->payment_hash);
339+
json_add_u64(req->js, "partid", route->key.partid);
340+
json_add_u64(req->js, "groupid", route->key.groupid);
341+
json_add_string(req->js, "invoice", pinfo->invstr);
342+
json_add_node_id(req->js, "destination", &pinfo->destination);
343+
json_add_amount_msat(req->js, "amount_msat", route->amount_deliver);
344+
json_add_amount_msat(req->js, "total_amount_msat", pinfo->amount);
345+
json_add_u32(req->js, "final_cltv", pinfo->final_cltv);
346+
347+
if (pinfo->label)
348+
json_add_string(req->js, "label", pinfo->label);
349+
if (pinfo->description)
350+
json_add_string(req->js, "description", pinfo->description);
351+
352+
json_array_start(req->js, "route");
353+
/* An empty route means a payment to oneself, pathlen=0 */
354+
for (size_t j = 0; j < pathlen; j++) {
355+
const struct route_hop *hop = &route->hops[j];
356+
json_object_start(req->js, NULL);
357+
json_add_node_id(req->js, "id", &hop->node_id);
358+
json_add_short_channel_id(req->js, "channel", hop->scid);
359+
json_add_amount_msat(req->js, "amount_msat", hop->amount);
360+
json_add_num(req->js, "direction", hop->direction);
361+
json_add_u32(req->js, "delay", hop->delay);
362+
json_add_string(req->js, "style", "tlv");
363+
json_object_end(req->js);
364+
}
365+
json_array_end(req->js);
366+
367+
/* Either we have a payment_secret for BOLT11 or blinded_paths for
368+
* BOLT12 */
369+
if (pinfo->payment_secret)
370+
json_add_secret(req->js, "payment_secret", pinfo->payment_secret);
371+
else {
372+
assert(pinfo->blinded_paths);
373+
const struct blinded_path *bpath =
374+
pinfo->blinded_paths[route->path_num];
375+
376+
// FIXME: how can we support the case when the entry point is a
377+
// scid?
378+
assert(bpath->first_node_id.is_pubkey);
379+
json_object_start(req->js, "blinded_path");
380+
json_add_pubkey(req->js, "first_node_id",
381+
&bpath->first_node_id.pubkey);
382+
json_add_pubkey(req->js, "first_path_key",
383+
&bpath->first_path_key);
384+
json_array_start(req->js, "path");
385+
for (size_t i = 0; i < tal_count(bpath->path); i++) {
386+
const struct blinded_path_hop *hop = bpath->path[i];
387+
json_object_start(req->js, NULL);
388+
json_add_pubkey(req->js, "blinded_node_id",
389+
&hop->blinded_node_id);
390+
json_add_hex_talarr(req->js, "encrypted_recipient_data",
391+
hop->encrypted_recipient_data);
392+
json_object_end(req->js);
393+
}
394+
json_array_end(req->js);
395+
json_object_end(req->js);
396+
}
338397

339398
route_map_add(payment->routetracker->sent_routes, route);
340-
if(taken(route))
399+
if (taken(route))
341400
tal_steal(payment->routetracker->sent_routes, route);
342401
return send_outreq(req);
343402
}

0 commit comments

Comments
 (0)