Skip to content

Commit

Permalink
listpays mod 1: add destination inside the response when bolt11 is null
Browse files Browse the repository at this point in the history
Changelog-Added: JSON-RPC: `listpays` now lists the `destination` if it was provided (e.g., via the `pay` plugin or `keysend` plugin)
  • Loading branch information
vincenzopalazzo authored and cdecker committed Aug 7, 2020
1 parent 816843a commit 751e66f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
6 changes: 5 additions & 1 deletion doc/lightning-sendonion.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion doc/lightning-sendonion.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ lightning-sendonion -- Send a payment with a custom onion packet
SYNOPSIS
--------

**sendonion** *onion* *first_hop* *payment_hash* \[*label*\] \[*shared_secrets*\] \[*partid*\] \[*bolt11*\] \[*msatoshi*\]
**sendonion** *onion* *first_hop* *payment_hash* \[*label*\] \[*shared_secrets*\] \[*partid*\] \[*bolt11*\]
\[*msatoshi*\] \[*destination*\]

DESCRIPTION
-----------
Expand Down Expand Up @@ -78,6 +79,8 @@ partial payments with the same *payment_hash*.
The *bolt11* parameter, if provided, will be returned in
*waitsendpay* and *listsendpays* results.

The *destination* parameter, if provided, will be returned in **listpays** result.

The *msatoshi* parameter is used to annotate the payment, and is returned by
*waitsendpay* and *listsendpays*.

Expand Down
4 changes: 3 additions & 1 deletion lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ static struct command_result *json_sendonion(struct command *cmd,
struct sha256 *payment_hash;
struct lightningd *ld = cmd->ld;
const char *label, *b11str;
struct node_id *destination;
struct secret *path_secrets;
struct amount_msat *msat;
u64 *partid;
Expand All @@ -1191,6 +1192,7 @@ static struct command_result *json_sendonion(struct command *cmd,
p_opt_def("partid", param_u64, &partid, 0),
p_opt("bolt11", param_string, &b11str),
p_opt_def("msatoshi", param_msat, &msat, AMOUNT_MSAT(0)),
p_opt("destination", param_node_id, &destination),
NULL))
return command_param_failed();

Expand All @@ -1204,7 +1206,7 @@ static struct command_result *json_sendonion(struct command *cmd,

return send_payment_core(ld, cmd, payment_hash, *partid,
first_hop, *msat, AMOUNT_MSAT(0),
label, b11str, &packet, NULL, NULL, NULL,
label, b11str, &packet, destination, NULL, NULL,
path_secrets);
}

Expand Down
3 changes: 3 additions & 0 deletions plugins/libplugin-pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,9 @@ static struct command_result *payment_createonion_success(struct command *cmd,
if (p->bolt11)
json_add_string(req->js, "bolt11", p->bolt11);

if (p->destination)
json_add_node_id(req->js, "destination", p->destination);

send_outreq(p->plugin, req);
return command_still_pending(cmd);
}
Expand Down
14 changes: 13 additions & 1 deletion plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,8 @@ struct pay_mpp {
* only). Null if we have any part for which we didn't know the
* amount. */
struct amount_msat *amount;

struct node_id *destination;
};

static const struct sha256 *pay_mpp_key(const struct pay_mpp *pm)
Expand Down Expand Up @@ -1736,6 +1738,9 @@ static void add_new_entry(struct json_stream *ret,
if (pm->b11)
json_add_string(ret, "bolt11", pm->b11);

if (pm->destination)
json_add_node_id(ret, "destination", pm->destination);

json_add_sha256(ret, "payment_hash", pm->payment_hash);
json_add_string(ret, "status", pm->status);
if (pm->label)
Expand Down Expand Up @@ -1780,23 +1785,29 @@ static struct command_result *listsendpays_done(struct command *cmd,
ret = jsonrpc_stream_success(cmd);
json_array_start(ret, "pays");
json_for_each_arr(i, t, arr) {
const jsmntok_t *status, *b11tok, *hashtok;
const jsmntok_t *status, *b11tok, *hashtok, *destinationtok;
const char *b11 = b11str;
struct sha256 payment_hash;
struct node_id destination;

b11tok = json_get_member(buf, t, "bolt11");
hashtok = json_get_member(buf, t, "payment_hash");
destinationtok = json_get_member(buf, t, "destination");
assert(hashtok != NULL);

json_to_sha256(buf, hashtok, &payment_hash);
if (b11tok)
b11 = json_strdup(cmd, buf, b11tok);

if (destinationtok)
json_to_node_id(buf, destinationtok, &destination);

pm = pay_map_get(&pay_map, &payment_hash);
if (!pm) {
pm = tal(cmd, struct pay_mpp);
pm->payment_hash = tal_dup(pm, struct sha256, &payment_hash);
pm->b11 = tal_steal(pm, b11);
pm->destination = tal_dup(pm,struct node_id, &destination);
pm->label = json_get_member(buf, t, "label");
pm->preimage = NULL;
pm->amount_sent = AMOUNT_MSAT(0);
Expand Down Expand Up @@ -1865,6 +1876,7 @@ static struct command_result *json_listpays(struct command *cmd,

if (payment_hash)
json_add_sha256(req->js, "payment_hash", payment_hash);

return send_outreq(cmd->plugin, req);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3260,6 +3260,8 @@ def test_listpay_result_with_paymod(node_factory, bitcoind):
l2.rpc.keysend(l3.info['id'], amount_sat * 2, "keysend_l3")

assert 'bolt11' in l1.rpc.listpays()['pays'][0]
assert 'bolt11' not in l2.rpc.listpays()['pays'][0]
assert 'payment_hash' in l2.rpc.listpays()['pays'][0]
assert 'payment_hash' in l1.rpc.listpays()['pays'][0]
assert 'bolt11' not in l2.rpc.listpays()['pays'][0]
assert 'destination' in l1.rpc.listpays()['pays'][0]
assert 'destination' in l2.rpc.listpays()['pays'][0]

0 comments on commit 751e66f

Please sign in to comment.