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

Function json_waitinvoice

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

1543 * waiters, if the payment is still pending.
1544 */
1545static 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
1578static const struct json_command waitinvoice_command = {
1579 "waitinvoice",

Callers

nothing calls this directly

Calls 10

tell_waiterFunction · 0.85
fixme_ignoreFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
command_still_pendingFunction · 0.70
command_its_complicatedFunction · 0.70
paramFunction · 0.50
wallet_invoice_detailsFunction · 0.50
wallet_invoice_waitoneFunction · 0.50

Tested by

no test coverage detected