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

Function json_sendinvoice

plugins/fetchinvoice.c:1556–1656  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1554}
1555
1556struct command_result *json_sendinvoice(struct command *cmd,
1557 const char *buffer,
1558 const jsmntok_t *params)
1559{
1560 const struct offers_data *od = get_offers_data(cmd->plugin);
1561 struct amount_msat *msat;
1562 u32 *timeout;
1563 struct sent *sent = tal(cmd, struct sent);
1564
1565 sent->offer = NULL;
1566 sent->cmd = cmd;
1567
1568 /* FIXME: Support recurring invoice_requests? */
1569 if (!param(cmd, buffer, params,
1570 p_req("invreq", param_invreq, &sent->invreq),
1571 p_req("label", param_label, &sent->inv_label),
1572 p_opt("amount_msat", param_msat, &msat),
1573 p_opt_def("timeout", param_number, &timeout, 90),
1574 NULL))
1575 return command_param_failed();
1576
1577 sent->dev_path_use_scidd = NULL;
1578 sent->dev_reply_path = NULL;
1579 sent->their_paths = sent->invreq->offer_paths;
1580 sent->direct_dest = sent->invreq->invreq_payer_id;
1581
1582 /* BOLT #12:
1583 * - if the invoice is in response to an `invoice_request`:
1584 * - MUST copy all non-signature fields from the invoice request
1585 * (including unknown fields).
1586 */
1587 sent->inv = invoice_for_invreq(sent, sent->invreq);
1588
1589 /* This is how long we'll wait for a reply for. */
1590 sent->wait_timeout = *timeout;
1591
1592 /* BOLT #12:
1593 * - if `invreq_amount` is present:
1594 * - MUST set `invoice_amount` to `invreq_amount`
1595 * - otherwise:
1596 * - MUST set `invoice_amount` to the *expected amount*.
1597 */
1598 if (!msat)
1599 sent->inv->invoice_amount = tal_dup(sent->inv, u64,
1600 sent->invreq->invreq_amount);
1601 else
1602 sent->inv->invoice_amount = tal_dup(sent->inv, u64,
1603 &msat->millisatoshis); /* Raw: tlv */
1604
1605 /* BOLT #12:
1606 * - MUST set `invoice_created_at` to the number of seconds since Midnight 1
1607 * January 1970, UTC when the invoice was created.
1608 * - MUST set `invoice_amount` to the minimum amount it will accept, in units of
1609 * the minimal lightning-payable unit (e.g. milli-satoshis for bitcoin) for
1610 * `invreq_chain`.
1611 */
1612 sent->inv->invoice_created_at = tal(sent->inv, u64);
1613 *sent->inv->invoice_created_at = clock_time().ts.tv_sec;

Callers

nothing calls this directly

Calls 10

get_offers_dataFunction · 0.85
invoice_for_invreqFunction · 0.85
clock_timeFunction · 0.85
invoice_recurrenceFunction · 0.85
sign_invoiceFunction · 0.85
command_param_failedFunction · 0.70
sha256Class · 0.70
command_failFunction · 0.70
plugin_feature_setFunction · 0.70
paramFunction · 0.50

Tested by

no test coverage detected