Browse Source

listpays: fixed bolt11 null with keysend and update doc command

listpays: make doc-all missed
Changelog-Added: JSON-RPC: `listpays` can be used to query payments using the `payment_hash`
Changelog-Added: JSON-RPC: `listpays` now includes the `payment_hash`
bump-pyln-proto
Vincent 5 years ago
committed by Christian Decker
parent
commit
700897f06e
  1. 14
      doc/lightning-listpays.7
  2. 13
      doc/lightning-listpays.7.md
  3. 10
      plugins/pay.c
  4. 24
      tests/test_pay.py

14
doc/lightning-listpays.7

@ -3,12 +3,12 @@
lightning-listpays - Command for querying payment status lightning-listpays - Command for querying payment status
.SH SYNOPSIS .SH SYNOPSIS
\fBlistpays\fR [bolt11] \fBlistpays\fR [bolt11] [payment_hash]
.SH DESCRIPTION .SH DESCRIPTION
The \fBlistpay\fR RPC command gets the status of all \fIpay\fR commands, or a The \fBlistpay\fR RPC command gets the status of all \fIpay\fR commands, or a
single one if \fIbolt11\fR is specified\. single one if either \fIbolt11\fR or \fIpayment_hash\fR was specified\.
.SH RETURN VALUE .SH RETURN VALUE
@ -16,7 +16,11 @@ On success, an array of objects is returned\. Each object contains:
\fIbolt11\fR \fIbolt11\fR
the \fIbolt11\fR argument given to \fIpay\fR (see below for exceptions)\. the \fIbolt11\fR invoice if provided to \fBpay\fR\.
\fIpayment_hash\fR
the \fIpayment_hash\fR of the payment\.
\fIstatus\fR \fIstatus\fR
@ -24,11 +28,11 @@ one of \fIcomplete\fR, \fIfailed\fR or \fIpending\fR\.
\fIpayment_preimage\fR \fIpayment_preimage\fR
(if \fIstatus\fR is \fIcomplete\fR) proves payment was received\. if \fIstatus\fR is \fIcomplete\fR\.
\fIlabel\fR \fIlabel\fR
optional \fIlabel\fR, if provided to \fIpay\fR\. optional \fIlabel\fR, if provided to \fIpay\fR or \fIsendonion\fR\.
\fIamount_sent_msat\fR \fIamount_sent_msat\fR

13
doc/lightning-listpays.7.md

@ -4,13 +4,13 @@ lightning-listpays -- Command for querying payment status
SYNOPSIS SYNOPSIS
-------- --------
**listpays** \[bolt11\] **listpays** \[bolt11\] \[payment_hash\]
DESCRIPTION DESCRIPTION
----------- -----------
The **listpay** RPC command gets the status of all *pay* commands, or a 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 RETURN VALUE
------------ ------------
@ -18,16 +18,19 @@ RETURN VALUE
On success, an array of objects is returned. Each object contains: On success, an array of objects is returned. Each object contains:
*bolt11* *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* *status*
one of *complete*, *failed* or *pending*. one of *complete*, *failed* or *pending*.
*payment\_preimage* *payment\_preimage*
(if *status* is *complete*) proves payment was received. if *status* is *complete*.
*label* *label*
optional *label*, if provided to *pay*. optional *label*, if provided to *pay* or *sendonion*.
*amount\_sent\_msat* *amount\_sent\_msat*
total amount sent, in "NNNmsat" format. total amount sent, in "NNNmsat" format.

10
plugins/pay.c

@ -1736,7 +1736,10 @@ static void add_new_entry(struct json_stream *ret,
const struct pay_mpp *pm) const struct pay_mpp *pm)
{ {
json_object_start(ret, NULL); json_object_start(ret, NULL);
if (pm->b11)
json_add_string(ret, "bolt11", pm->b11); json_add_string(ret, "bolt11", pm->b11);
json_add_sha256(ret, "payment_hash", pm->payment_hash);
json_add_string(ret, "status", pm->status); json_add_string(ret, "status", pm->status);
json_add_u32(ret, "created_at", pm->timestamp); json_add_u32(ret, "created_at", pm->timestamp);
@ -1854,11 +1857,13 @@ static struct command_result *json_listpays(struct command *cmd,
const jsmntok_t *params) const jsmntok_t *params)
{ {
const char *b11str; const char *b11str;
struct sha256 *payment_hash;
struct out_req *req; struct out_req *req;
/* FIXME: would be nice to parse as a bolt11 so check worked in future */ /* FIXME: would be nice to parse as a bolt11 so check worked in future */
if (!param(cmd, buf, params, if (!param(cmd, buf, params,
p_opt("bolt11", param_string, &b11str), p_opt("bolt11", param_string, &b11str),
p_opt("payment_hash", param_sha256, &payment_hash),
NULL)) NULL))
return command_param_failed(); return command_param_failed();
@ -1867,6 +1872,9 @@ static struct command_result *json_listpays(struct command *cmd,
cast_const(char *, b11str)); cast_const(char *, b11str));
if (b11str) if (b11str)
json_add_string(req->js, "bolt11", 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); return send_outreq(cmd->plugin, req);
} }
@ -2054,7 +2062,7 @@ static const struct plugin_command commands[] = {
}, { }, {
"listpays", "listpays",
"payment", "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.", "Covers old payments (failed and succeeded) and current ones.",
json_listpays json_listpays
}, },

24
tests/test_pay.py

@ -3240,3 +3240,27 @@ def test_mpp_presplit_routehint_conflict(node_factory, bitcoind):
inv = l3.rpc.invoice(Millisatoshi(2 * 10000 * 1000), 'i', 'i', exposeprivatechannels=True)['bolt11'] inv = l3.rpc.invoice(Millisatoshi(2 * 10000 * 1000), 'i', 'i', exposeprivatechannels=True)['bolt11']
l1.rpc.pay(inv) 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 '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]

Loading…
Cancel
Save