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

Function json_createinvoice

lightningd/invoice.c:1672–1846  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1670}
1671
1672static struct command_result *json_createinvoice(struct command *cmd,
1673 const char *buffer,
1674 const jsmntok_t *obj UNNEEDED,
1675 const jsmntok_t *params)
1676{
1677 const char *invstring;
1678 struct json_escape *label;
1679 struct preimage *preimage;
1680 u64 inv_dbid;
1681 struct sha256 payment_hash;
1682 struct json_stream *response;
1683 struct bolt11 *b11;
1684 struct sha256 hash;
1685 const u5 *sig;
1686 bool have_n;
1687 const char *fail;
1688
1689 if (!param_check(cmd, buffer, params,
1690 p_req("invstring", param_invstring, &invstring),
1691 p_req("label", param_label, &label),
1692 p_req("preimage", param_preimage, &preimage),
1693 NULL))
1694 return command_param_failed();
1695
1696 sha256(&payment_hash, preimage, sizeof(*preimage));
1697 b11 = bolt11_decode_nosig(cmd, invstring, cmd->ld->our_features,
1698 NULL, chainparams, &hash, &sig, &have_n,
1699 &fail);
1700 if (b11) {
1701 /* Same bound as the invoice RPC: past 60 bits
1702 * bolt11_encode() below aborts, and the expiry timer
1703 * overflows its u64 nanosecond grain far below that. */
1704 if (b11->expiry >= (u64)1 << 32)
1705 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1706 "expiry must be below 2^32 seconds"
1707 " (~136 years)");
1708
1709 /* This adds the signature */
1710 char *b11enc = bolt11_encode(cmd, b11, have_n,
1711 hsm_sign_b11, cmd->ld);
1712
1713 if (!b11->description)
1714 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1715 "Missing description in invoice");
1716
1717 if (!b11->expiry)
1718 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1719 "Missing expiry in invoice");
1720
1721 if (!sha256_eq(&payment_hash, &b11->payment_hash))
1722 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1723 "Incorrect preimage");
1724
1725 if (command_check_only(cmd))
1726 return command_check_done(cmd);
1727
1728 if (!invoices_create(cmd->ld->wallet->invoices,
1729 &inv_dbid,

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
bolt11_decode_nosigFunction · 0.85
fail_existsFunction · 0.85
invoice_decode_minimalFunction · 0.85
add_stub_blindedpathFunction · 0.85
hsm_sign_b12_invoiceFunction · 0.85
invoice_encodeFunction · 0.85
invoice_offer_idFunction · 0.85
offer_status_activeFunction · 0.85
tal_bytelenFunction · 0.85
command_param_failedFunction · 0.70
sha256Class · 0.70

Tested by

no test coverage detected