Wait for an incoming payment matching the `label` in the JSON * command. This will either return immediately if the payment has * already been received or it may add the `cmd` to the list of * waiters, if the payment is still pending. */
| 1552 | * waiters, if the payment is still pending. |
| 1553 | */ |
| 1554 | static struct command_result *json_waitinvoice(struct command *cmd, |
| 1555 | const char *buffer, |
| 1556 | const jsmntok_t *obj UNNEEDED, |
| 1557 | const jsmntok_t *params) |
| 1558 | { |
| 1559 | u64 inv_dbid; |
| 1560 | const struct invoice_details *details; |
| 1561 | struct wallet *wallet = cmd->ld->wallet; |
| 1562 | struct json_escape *label; |
| 1563 | |
| 1564 | if (!param_check(cmd, buffer, params, |
| 1565 | p_req("label", param_label, &label), |
| 1566 | NULL)) |
| 1567 | return command_param_failed(); |
| 1568 | |
| 1569 | if (!invoices_find_by_label(wallet->invoices, &inv_dbid, label)) { |
| 1570 | return command_fail(cmd, LIGHTNINGD, "Label not found"); |
| 1571 | } |
| 1572 | if (command_check_only(cmd)) |
| 1573 | return command_check_done(cmd); |
| 1574 | |
| 1575 | details = invoices_get_details(cmd, cmd->ld->wallet->invoices, inv_dbid); |
| 1576 | |
| 1577 | /* If paid or expired return immediately */ |
| 1578 | if (details->state == PAID || details->state == EXPIRED) { |
| 1579 | return tell_waiter(cmd, inv_dbid); |
| 1580 | } else { |
| 1581 | /* There is an unpaid one matching, let's wait... */ |
| 1582 | fixme_ignore(command_still_pending(cmd)); |
| 1583 | invoices_waitone(cmd, wallet->invoices, inv_dbid, |
| 1584 | &wait_on_invoice, (void *) cmd); |
| 1585 | return command_its_complicated("wallet_invoice_waitone might" |
| 1586 | " complete immediately"); |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | static const struct json_command waitinvoice_command = { |
| 1591 | "waitinvoice", |
nothing calls this directly
no test coverage detected