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

Function json_createinvoice

lightningd/invoice.c:1643–1781  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1641}
1642
1643static struct command_result *json_createinvoice(struct command *cmd,
1644 const char *buffer,
1645 const jsmntok_t *obj UNNEEDED,
1646 const jsmntok_t *params)
1647{
1648 const char *invstring;
1649 struct json_escape *label;
1650 struct preimage *preimage;
1651 struct invoice invoice;
1652 struct sha256 payment_hash;
1653 struct json_stream *response;
1654 struct bolt11 *b11;
1655 struct sha256 hash;
1656 u5 *sig;
1657 bool have_n;
1658 char *fail;
1659
1660 if (!param(cmd, buffer, params,
1661 p_req("invstring", param_string, &invstring),
1662 p_req("label", param_label, &label),
1663 p_req("preimage", param_preimage, &preimage),
1664 NULL))
1665 return command_param_failed();
1666
1667 sha256(&payment_hash, preimage, sizeof(*preimage));
1668 b11 = bolt11_decode_nosig(cmd, invstring, cmd->ld->our_features,
1669 NULL, chainparams, &hash, &sig, &have_n,
1670 &fail);
1671 if (b11) {
1672 /* This adds the signature */
1673 char *b11enc = bolt11_encode(cmd, b11, have_n,
1674 hsm_sign_b11, cmd->ld);
1675
1676 if (!b11->description)
1677 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1678 "Missing description in invoice");
1679
1680 if (!b11->expiry)
1681 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1682 "Missing expiry in invoice");
1683
1684 if (!sha256_eq(&payment_hash, &b11->payment_hash))
1685 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1686 "Incorrect preimage");
1687
1688 if (!wallet_invoice_create(cmd->ld->wallet,
1689 &invoice,
1690 b11->msat,
1691 label,
1692 b11->expiry,
1693 b11enc,
1694 b11->description,
1695 b11->features,
1696 preimage,
1697 &payment_hash,
1698 NULL))
1699 return fail_exists(cmd, label);
1700

Callers

nothing calls this directly

Calls 15

fail_existsFunction · 0.85
hsm_sign_b12_invoiceFunction · 0.85
offer_status_activeFunction · 0.85
tal_bytelenFunction · 0.85
json_add_invoice_fieldsFunction · 0.85
command_param_failedFunction · 0.70
sha256Class · 0.70
command_failFunction · 0.70
notify_invoice_creationFunction · 0.70
amount_msatClass · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70

Tested by

no test coverage detected