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

Support the the filtering option by status in the listpays and listsendpays #4595

Merged
13 changes: 8 additions & 5 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,15 +931,17 @@ def listnodes(self, node_id=None):
}
return self.call("listnodes", payload)

def listpays(self, bolt11=None, payment_hash=None):
def listpays(self, bolt11=None, payment_hash=None, status=None):
"""
Show outgoing payments, regarding {bolt11} or {payment_hash} if set
Can only specify one of {bolt11} or {payment_hash}.
Can only specify one of {bolt11} or {payment_hash}. It is possible
filter the payments by {status}.
"""
assert not (bolt11 and payment_hash)
payload = {
"bolt11": bolt11,
"payment_hash": payment_hash
"payment_hash": payment_hash,
"status": status
}
return self.call("listpays", payload)

Expand All @@ -953,11 +955,12 @@ def listpeers(self, peerid=None, level=None):
}
return self.call("listpeers", payload)

def listsendpays(self, bolt11=None, payment_hash=None):
def listsendpays(self, bolt11=None, payment_hash=None, status=None):
"""Show all sendpays results, or only for `bolt11` or `payment_hash`."""
payload = {
"bolt11": bolt11,
"payment_hash": payment_hash
"payment_hash": payment_hash,
"status": status
}
return self.call("listsendpays", payload)

Expand Down
5 changes: 3 additions & 2 deletions doc/lightning-listpays.7

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

3 changes: 2 additions & 1 deletion doc/lightning-listpays.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ lightning-listpays -- Command for querying payment status
SYNOPSIS
--------

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

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

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

RETURN VALUE
------------
Expand Down
6 changes: 3 additions & 3 deletions doc/lightning-listsendpays.7

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

4 changes: 2 additions & 2 deletions doc/lightning-listsendpays.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ lightning-listsendpays -- Low-level command for querying sendpay status
SYNOPSIS
--------

**listsendpays** \[*bolt11*\] \[*payment\_hash*\]
**listsendpays** \[*bolt11*\] \[*payment\_hash*\] \[*status*\]

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

The **listsendpays** RPC command gets the status of all *sendpay*
commands (which is also used by the *pay* command), or with *bolt11* or
*payment\_hash* limits results to that specific payment. You cannot
specify both.
specify both. It is possible filter the payments also by *status*.

Note that in future there may be more than one concurrent *sendpay*
command per *pay*, so this command should be used with caution.
Expand Down
2 changes: 1 addition & 1 deletion lightningd/offer.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static struct command_result *prev_payment(struct command *cmd,
bool prev_paid = false;

assert(!invreq->payer_info);
payments = wallet_payment_list(cmd, cmd->ld->wallet, NULL);
payments = wallet_payment_list(cmd, cmd->ld->wallet, NULL, NULL);

for (size_t i = 0; i < tal_count(payments); i++) {
const struct tlv_invoice *inv;
Expand Down
16 changes: 12 additions & 4 deletions lightningd/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ send_payment_core(struct lightningd *ld,
bool have_complete = false;

/* Now, do we already have one or more payments? */
payments = wallet_payment_list(tmpctx, ld->wallet, rhash);
payments = wallet_payment_list(tmpctx, ld->wallet, rhash, NULL);
for (size_t i = 0; i < tal_count(payments); i++) {
log_debug(ld->log, "Payment %zu/%zu: %s %s",
i, tal_count(payments),
Expand Down Expand Up @@ -1516,12 +1516,13 @@ static struct command_result *json_listsendpays(struct command *cmd,
const struct wallet_payment **payments;
struct json_stream *response;
struct sha256 *rhash;
const char *invstring;
const char *invstring, *status_str;

if (!param(cmd, buffer, params,
/* FIXME: parameter should be invstring now */
p_opt("bolt11", param_string, &invstring),
p_opt("payment_hash", param_sha256, &rhash),
p_opt("status", param_string, &status_str),
NULL))
return command_param_failed();

Expand Down Expand Up @@ -1553,7 +1554,14 @@ static struct command_result *json_listsendpays(struct command *cmd,
}
}

payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash);
if (status_str) {
enum wallet_payment_status status;

if (!string_to_payment_status(status_str, &status))
return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Unrecognized status: %s", status_str);
payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash, &status);
} else
payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash, NULL);

response = json_stream_success(cmd);

Expand Down Expand Up @@ -1606,7 +1614,7 @@ static struct command_result *json_delpay(struct command *cmd,
payment_status_to_string(status));
}

payments = wallet_payment_list(cmd, cmd->ld->wallet, payment_hash);
payments = wallet_payment_list(cmd, cmd->ld->wallet, payment_hash, NULL);

if (tal_count(payments) == 0)
return command_fail(cmd, PAY_NO_SUCH_PAYMENT, "Unknown payment with payment_hash: %s",
Expand Down
5 changes: 4 additions & 1 deletion plugins/pay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ static struct command_result *json_listpays(struct command *cmd,
const char *buf,
const jsmntok_t *params)
{
const char *invstring;
const char *invstring, *status_str;
struct sha256 *payment_hash;
struct out_req *req;

Expand All @@ -1903,6 +1903,7 @@ static struct command_result *json_listpays(struct command *cmd,
/* FIXME: parameter should be invstring now */
p_opt("bolt11", param_string, &invstring),
p_opt("payment_hash", param_sha256, &payment_hash),
p_opt("status", param_string, &status_str),
NULL))
return command_param_failed();

Expand All @@ -1915,6 +1916,8 @@ static struct command_result *json_listpays(struct command *cmd,
if (payment_hash)
json_add_sha256(req->js, "payment_hash", payment_hash);

if (status_str)
json_add_string(req->js, "status", status_str);
return send_outreq(cmd->plugin, req);
}

Expand Down
23 changes: 23 additions & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4603,3 +4603,26 @@ def test_pay_low_max_htlcs(node_factory):
l1.daemon.wait_for_log(
r'Number of pre-split HTLCs \([0-9]+\) exceeds our HTLC budget \([0-9]+\), skipping pre-splitter'
)


def test_listpays_with_filter_by_status(node_factory, bitcoind):
"""
This test check if the filtering by status of the command listpays
has some mistakes.
"""

# Create the line graph l2 -> l1 with a channel of 10 ** 5 sat!
l2, l1 = node_factory.line_graph(2, fundamount=10**5, wait_for_announce=True)

inv = l1.rpc.invoice(10 ** 5, 'inv', 'inv')
l2.rpc.pay(inv['bolt11'])

wait_for(lambda: l2.rpc.listpays(inv['bolt11'])['pays'][0]['status'] == 'complete')

# test if the node is still ready
payments = l2.rpc.listpays(status='failed')

assert len(payments['pays']) == 0

payments = l2.rpc.listpays()
assert len(l2.rpc.listpays()['pays']) == 1
16 changes: 5 additions & 11 deletions wallet/db_postgres_sqlgen.c

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

16 changes: 5 additions & 11 deletions wallet/db_sqlite3_sqlgen.c

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

Loading