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

Function json_sendinvoice

plugins/fetchinvoice.c:1534–1718  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1532}
1533
1534static struct command_result *json_sendinvoice(struct command *cmd,
1535 const char *buffer,
1536 const jsmntok_t *params)
1537{
1538 struct amount_msat *msat;
1539 struct out_req *req;
1540 u32 *timeout;
1541 struct sent *sent = tal(cmd, struct sent);
1542
1543 sent->inv = tlv_invoice_new(cmd);
1544 sent->invreq = NULL;
1545 sent->cmd = cmd;
1546
1547 /* FIXME: Support recurring send_invoice offers? */
1548 if (!param(cmd, buffer, params,
1549 p_req("offer", param_offer, &sent->offer),
1550 p_req("label", param_label, &sent->inv_label),
1551 p_opt("amount_msat|msatoshi", param_msat, &msat),
1552 p_opt_def("timeout", param_number, &timeout, 90),
1553 p_opt("quantity", param_u64, &sent->inv->quantity),
1554 NULL))
1555 return command_param_failed();
1556
1557 /* This is how long we'll wait for a reply for. */
1558 sent->wait_timeout = *timeout;
1559
1560 /* Check they are really trying to send us money. */
1561 if (!sent->offer->send_invoice)
1562 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1563 "Offer wants an invoice_request, not invoice");
1564
1565 /* If they don't tell us how much, base it on offer. */
1566 if (!msat) {
1567 if (sent->offer->currency)
1568 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1569 "Offer in different currency: need amount");
1570 if (!sent->offer->amount)
1571 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1572 "Offer did not specify: need amount");
1573 sent->inv->amount = tal_dup(sent->inv, u64, sent->offer->amount);
1574 if (sent->inv->quantity)
1575 *sent->inv->amount *= *sent->inv->quantity;
1576 } else
1577 sent->inv->amount = tal_dup(sent->inv, u64,
1578 &msat->millisatoshis); /* Raw: tlv */
1579
1580 /* FIXME: Support blinded paths, in which case use fake nodeid */
1581
1582 /* BOLT-offers #12:
1583 * - otherwise (responding to a `send_invoice` offer):
1584 * - MUST set `node_id` to the id of the node to send payment to.
1585 * - MUST set `description` the same as the offer.
1586 */
1587 sent->inv->node_id = tal(sent->inv, struct point32);
1588
1589 /* This only fails if pubkey is invalid. */
1590 if (!secp256k1_xonly_pubkey_from_pubkey(secp256k1_ctx,
1591 &sent->inv->node_id->pubkey,

Callers

nothing calls this directly

Calls 11

abortFunction · 0.85
time_nowFunction · 0.85
plugin_feature_setFunction · 0.85
sign_invoiceFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
sha256Class · 0.70
send_outreqFunction · 0.70
paramFunction · 0.50
merkle_tlvFunction · 0.50
json_add_sha256Function · 0.50

Tested by

no test coverage detected