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. */
| 1543 | * waiters, if the payment is still pending. |
| 1544 | */ |
| 1545 | static struct command_result *json_waitinvoice(struct command *cmd, |
| 1546 | const char *buffer, |
| 1547 | const jsmntok_t *obj UNNEEDED, |
| 1548 | const jsmntok_t *params) |
| 1549 | { |
| 1550 | struct invoice i; |
| 1551 | const struct invoice_details *details; |
| 1552 | struct wallet *wallet = cmd->ld->wallet; |
| 1553 | struct json_escape *label; |
| 1554 | |
| 1555 | if (!param(cmd, buffer, params, |
| 1556 | p_req("label", param_label, &label), |
| 1557 | NULL)) |
| 1558 | return command_param_failed(); |
| 1559 | |
| 1560 | if (!wallet_invoice_find_by_label(wallet, &i, label)) { |
| 1561 | return command_fail(cmd, LIGHTNINGD, "Label not found"); |
| 1562 | } |
| 1563 | details = wallet_invoice_details(cmd, cmd->ld->wallet, i); |
| 1564 | |
| 1565 | /* If paid or expired return immediately */ |
| 1566 | if (details->state == PAID || details->state == EXPIRED) { |
| 1567 | return tell_waiter(cmd, &i); |
| 1568 | } else { |
| 1569 | /* There is an unpaid one matching, let's wait... */ |
| 1570 | fixme_ignore(command_still_pending(cmd)); |
| 1571 | wallet_invoice_waitone(cmd, wallet, i, |
| 1572 | &wait_on_invoice, (void *) cmd); |
| 1573 | return command_its_complicated("wallet_invoice_waitone might" |
| 1574 | " complete immediately"); |
| 1575 | } |
| 1576 | } |
| 1577 | |
| 1578 | static const struct json_command waitinvoice_command = { |
| 1579 | "waitinvoice", |
nothing calls this directly
no test coverage detected