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

Function json_waitinvoice

lightningd/invoice.c:1554–1588  ·  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

1552 * waiters, if the payment is still pending.
1553 */
1554static 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
1590static const struct json_command waitinvoice_command = {
1591 "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