MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_waitinvoice

Function json_waitinvoice

lightningd/invoice.c:1541–1575  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

1539 * waiters, if the payment is still pending.
1540 */
1541static 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
1577static const struct json_command waitinvoice_command = {
1578 "waitinvoice",

Callers

nothing calls this directly

Calls 12

param_checkFunction · 0.85
tell_waiterFunction · 0.85
fixme_ignoreFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70
command_still_pendingFunction · 0.70
command_its_complicatedFunction · 0.70
invoices_find_by_labelFunction · 0.50
invoices_get_detailsFunction · 0.50
invoices_waitoneFunction · 0.50

Tested by

no test coverage detected