Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update format response from listpay is the payment was did with keysend #3888

Merged
merged 2 commits into from
Aug 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions doc/lightning-listpays.7

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

13 changes: 8 additions & 5 deletions doc/lightning-listpays.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,33 @@ lightning-listpays -- Command for querying payment status
SYNOPSIS
--------

**listpays** \[bolt11\]
**listpays** \[bolt11\] \[payment_hash\]

DESCRIPTION
-----------

The **listpay** RPC command gets the status of all *pay* commands, or a
single one if *bolt11* is specified.
single one if either *bolt11* or *payment_hash* was specified.

RETURN VALUE
------------

On success, an array of objects is returned. Each object contains:

*bolt11*
the *bolt11* argument given to *pay* (see below for exceptions).
the *bolt11* invoice if provided to `pay`.

*payment_hash*
the *payment_hash* of the payment.

*status*
one of *complete*, *failed* or *pending*.

*payment\_preimage*
(if *status* is *complete*) proves payment was received.
if *status* is *complete*.

*label*
optional *label*, if provided to *pay*.
optional *label*, if provided to *pay* or *sendonion*.

*amount\_sent\_msat*
total amount sent, in "NNNmsat" format.
Expand Down
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
27 changes: 24 additions & 3 deletions plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,9 @@ struct pay_mpp {

/* Timestamp of the first part */
u32 timestamp;

/* The destination of the payment, if specified. */
struct node_id *destination;
};

static const struct sha256 *pay_mpp_key(const struct pay_mpp *pm)
Expand Down Expand Up @@ -1736,7 +1739,13 @@ static void add_new_entry(struct json_stream *ret,
const struct pay_mpp *pm)
{
json_object_start(ret, NULL);
json_add_string(ret, "bolt11", pm->b11);
if (pm->b11)
json_add_string(ret, "bolt11", pm->b11);

if (pm->destination)
json_add_node_id(ret, "destination", pm->destination);
cdecker marked this conversation as resolved.
Show resolved Hide resolved

json_add_sha256(ret, "payment_hash", pm->payment_hash);
json_add_string(ret, "status", pm->status);
json_add_u32(ret, "created_at", pm->timestamp);

Expand Down Expand Up @@ -1782,13 +1791,15 @@ 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, *createdtok;
const jsmntok_t *status, *b11tok, *hashtok, *destinationtok, *createdtok;
const char *b11 = b11str;
struct sha256 payment_hash;
struct node_id destination;
u32 created_at;

b11tok = json_get_member(buf, t, "bolt11");
hashtok = json_get_member(buf, t, "payment_hash");
destinationtok = json_get_member(buf, t, "destination");
createdtok = json_get_member(buf, t, "created_at");
assert(hashtok != NULL);
assert(createdtok != NULL);
Expand All @@ -1798,11 +1809,15 @@ static struct command_result *listsendpays_done(struct command *cmd,
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 @@ -1854,11 +1869,13 @@ static struct command_result *json_listpays(struct command *cmd,
const jsmntok_t *params)
{
const char *b11str;
struct sha256 *payment_hash;
struct out_req *req;

/* FIXME: would be nice to parse as a bolt11 so check worked in future */
if (!param(cmd, buf, params,
p_opt("bolt11", param_string, &b11str),
p_opt("payment_hash", param_sha256, &payment_hash),
NULL))
return command_param_failed();

Expand All @@ -1867,6 +1884,10 @@ static struct command_result *json_listpays(struct command *cmd,
cast_const(char *, b11str));
if (b11str)
json_add_string(req->js, "bolt11", b11str);

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

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

Expand Down Expand Up @@ -2054,7 +2075,7 @@ static const struct plugin_command commands[] = {
}, {
"listpays",
"payment",
"List result of payment {bolt11}, or all",
"List result of payment {bolt11} or {payment_hash}, or all",
"Covers old payments (failed and succeeded) and current ones.",
json_listpays
},
Expand Down
26 changes: 26 additions & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3240,3 +3240,29 @@ def test_mpp_presplit_routehint_conflict(node_factory, bitcoind):
inv = l3.rpc.invoice(Millisatoshi(2 * 10000 * 1000), 'i', 'i', exposeprivatechannels=True)['bolt11']

l1.rpc.pay(inv)


def test_listpay_result_with_paymod(node_factory, bitcoind):
"""
The object of this test is to verify the correct behavior
of the RPC command listpay e with two different type of
payment, such as: keysend (without invoice) and pay (with invoice).
l1 -> keysend -> l2
l2 -> pay invoice -> l3
"""

amount_sat = 10 ** 6

l1, l2, l3 = node_factory.line_graph(3)

invl2 = l2.rpc.invoice(amount_sat * 2, "inv_l2", "inv_l2")
l1.rpc.pay(invl2['bolt11'])

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 'destination' in l1.rpc.listpays()['pays'][0]
assert 'destination' in l2.rpc.listpays()['pays'][0]