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