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

Function json_sendinvoice

plugins/fetchinvoice.c:1647–1747  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1645}
1646
1647struct command_result *json_sendinvoice(struct command *cmd,
1648 const char *buffer,
1649 const jsmntok_t *params)
1650{
1651 const struct offers_data *od = get_offers_data(cmd->plugin);
1652 struct amount_msat *msat;
1653 u32 *timeout;
1654 struct sent *sent = tal(cmd, struct sent);
1655
1656 sent->offer = NULL;
1657 sent->cmd = cmd;
1658
1659 /* FIXME: Support recurring invoice_requests? */
1660 if (!param(cmd, buffer, params,
1661 p_req("invreq", param_invreq, &sent->invreq),
1662 p_req("label", param_label, &sent->inv_label),
1663 p_opt("amount_msat", param_msat, &msat),
1664 p_opt_def("timeout", param_number, &timeout, 90),
1665 NULL))
1666 return command_param_failed();
1667
1668 sent->dev_path_use_scidd = NULL;
1669 sent->dev_reply_path = NULL;
1670 sent->their_paths = sent->invreq->offer_paths;
1671 sent->direct_dest = sent->invreq->invreq_payer_id;
1672
1673 /* BOLT #12:
1674 * - if the invoice is in response to an `invoice_request`:
1675 * - MUST copy all non-signature fields from the invoice request
1676 * (including unknown fields).
1677 */
1678 sent->inv = invoice_for_invreq(sent, sent->invreq);
1679
1680 /* This is how long we'll wait for a reply for. */
1681 sent->wait_timeout = *timeout;
1682
1683 /* BOLT #12:
1684 * - if `invreq_amount` is present:
1685 * - MUST set `invoice_amount` to `invreq_amount`
1686 * - otherwise:
1687 * - MUST set `invoice_amount` to the *expected amount*.
1688 */
1689 if (!msat)
1690 sent->inv->invoice_amount = tal_dup(sent->inv, u64,
1691 sent->invreq->invreq_amount);
1692 else
1693 sent->inv->invoice_amount = tal_dup(sent->inv, u64,
1694 &msat->millisatoshis); /* Raw: tlv */
1695
1696 /* BOLT #12:
1697 * - MUST set `invoice_created_at` to the number of seconds since Midnight 1
1698 * January 1970, UTC when the invoice was created.
1699 * - MUST set `invoice_amount` to the minimum amount it will accept, in units of
1700 * the minimal lightning-payable unit (e.g. milli-satoshis for bitcoin) for
1701 * `invreq_chain`.
1702 */
1703 sent->inv->invoice_created_at = tal(sent->inv, u64);
1704 *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