| 1487 | AUTODATA(json_command, &delinvoice_command); |
| 1488 | |
| 1489 | static struct command_result *json_waitanyinvoice(struct command *cmd, |
| 1490 | const char *buffer, |
| 1491 | const jsmntok_t *obj UNNEEDED, |
| 1492 | const jsmntok_t *params) |
| 1493 | { |
| 1494 | u64 *pay_index; |
| 1495 | u64 *timeout; |
| 1496 | struct wallet *wallet = cmd->ld->wallet; |
| 1497 | |
| 1498 | if (!param(cmd, buffer, params, |
| 1499 | p_opt_def("lastpay_index", param_u64, &pay_index, 0), |
| 1500 | p_opt("timeout", ¶m_u64, &timeout), |
| 1501 | NULL)) |
| 1502 | return command_param_failed(); |
| 1503 | |
| 1504 | /*~ We allocate the timeout and the wallet-waitanyinvoice |
| 1505 | * in the cmd context, so whichever one manages to complete |
| 1506 | * the command first (and destroy the cmd context) |
| 1507 | * auto-cancels the other, is not tal amazing? |
| 1508 | */ |
| 1509 | if (timeout) |
| 1510 | (void) new_reltimer(cmd->ld->timers, cmd, |
| 1511 | time_from_sec(*timeout), |
| 1512 | &wait_timed_out, cmd); |
| 1513 | |
| 1514 | /* Set command as pending. We do not know if |
| 1515 | * wallet_invoice_waitany will return immediately |
| 1516 | * or not, so indicating pending is safest. */ |
| 1517 | fixme_ignore(command_still_pending(cmd)); |
| 1518 | |
| 1519 | /* Find next paid invoice. */ |
| 1520 | invoices_waitany(cmd, wallet->invoices, *pay_index, |
| 1521 | &wait_on_invoice, (void*) cmd); |
| 1522 | |
| 1523 | return command_its_complicated("wallet_invoice_waitany might complete" |
| 1524 | " immediately, but we also call it as a" |
| 1525 | " callback so plumbing through the return" |
| 1526 | " is non-trivial."); |
| 1527 | } |
| 1528 | |
| 1529 | |
| 1530 | static const struct json_command waitanyinvoice_command = { |
nothing calls this directly
no test coverage detected