| 1657 | } |
| 1658 | |
| 1659 | static struct command_result *json_createinvoice(struct command *cmd, |
| 1660 | const char *buffer, |
| 1661 | const jsmntok_t *obj UNNEEDED, |
| 1662 | const jsmntok_t *params) |
| 1663 | { |
| 1664 | const char *invstring; |
| 1665 | struct json_escape *label; |
| 1666 | struct preimage *preimage; |
| 1667 | u64 inv_dbid; |
| 1668 | struct sha256 payment_hash; |
| 1669 | struct json_stream *response; |
| 1670 | struct bolt11 *b11; |
| 1671 | struct sha256 hash; |
| 1672 | const u5 *sig; |
| 1673 | bool have_n; |
| 1674 | const char *fail; |
| 1675 | |
| 1676 | if (!param_check(cmd, buffer, params, |
| 1677 | p_req("invstring", param_invstring, &invstring), |
| 1678 | p_req("label", param_label, &label), |
| 1679 | p_req("preimage", param_preimage, &preimage), |
| 1680 | NULL)) |
| 1681 | return command_param_failed(); |
| 1682 | |
| 1683 | sha256(&payment_hash, preimage, sizeof(*preimage)); |
| 1684 | b11 = bolt11_decode_nosig(cmd, invstring, cmd->ld->our_features, |
| 1685 | NULL, chainparams, &hash, &sig, &have_n, |
| 1686 | &fail); |
| 1687 | if (b11) { |
| 1688 | /* This adds the signature */ |
| 1689 | char *b11enc = bolt11_encode(cmd, b11, have_n, |
| 1690 | hsm_sign_b11, cmd->ld); |
| 1691 | |
| 1692 | if (!b11->description) |
| 1693 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1694 | "Missing description in invoice"); |
| 1695 | |
| 1696 | if (!b11->expiry) |
| 1697 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1698 | "Missing expiry in invoice"); |
| 1699 | |
| 1700 | if (!sha256_eq(&payment_hash, &b11->payment_hash)) |
| 1701 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1702 | "Incorrect preimage"); |
| 1703 | |
| 1704 | if (command_check_only(cmd)) |
| 1705 | return command_check_done(cmd); |
| 1706 | |
| 1707 | if (!invoices_create(cmd->ld->wallet->invoices, |
| 1708 | &inv_dbid, |
| 1709 | b11->msat, |
| 1710 | label, |
| 1711 | b11->expiry, |
| 1712 | b11enc, |
| 1713 | b11->description, |
| 1714 | b11->features, |
| 1715 | preimage, |
| 1716 | &payment_hash, |
nothing calls this directly
no test coverage detected