| 1108 | } |
| 1109 | |
| 1110 | static struct command_result *json_invoice(struct command *cmd, |
| 1111 | const char *buffer, |
| 1112 | const jsmntok_t *obj UNNEEDED, |
| 1113 | const jsmntok_t *params) |
| 1114 | { |
| 1115 | const jsmntok_t *fallbacks; |
| 1116 | struct amount_msat *msatoshi_val; |
| 1117 | struct invoice_info *info; |
| 1118 | const char *desc_val; |
| 1119 | const u8 **fallback_scripts = NULL; |
| 1120 | u64 *expiry; |
| 1121 | struct sha256 rhash; |
| 1122 | struct secret payment_secret; |
| 1123 | struct preimage *preimage; |
| 1124 | u32 *cltv; |
| 1125 | struct jsonrpc_request *req; |
| 1126 | struct plugin *plugin; |
| 1127 | bool *hashonly; |
| 1128 | const size_t inv_max_label_len = 128; |
| 1129 | const jsmntok_t *dev_routes; |
| 1130 | |
| 1131 | info = tal(cmd, struct invoice_info); |
| 1132 | info->cmd = cmd; |
| 1133 | |
| 1134 | if (!param_check(cmd, buffer, params, |
| 1135 | p_req("amount_msat", param_positive_msat_or_any, &msatoshi_val), |
| 1136 | p_req("label", param_label, &info->label), |
| 1137 | p_req("description", param_escaped_string, &desc_val), |
| 1138 | p_opt_def("expiry", param_u64, &expiry, 3600*24*7), |
| 1139 | p_opt("fallbacks", param_array, &fallbacks), |
| 1140 | p_opt("preimage", param_preimage, &preimage), |
| 1141 | p_opt("exposeprivatechannels", param_chanhints, |
| 1142 | &info->chanhints), |
| 1143 | p_opt_def("cltv", param_number, &cltv, |
| 1144 | cmd->ld->config.cltv_final), |
| 1145 | p_opt_def("deschashonly", param_bool, &hashonly, false), |
| 1146 | p_opt("dev-routes", param_array, &dev_routes), |
| 1147 | NULL)) |
| 1148 | return command_param_failed(); |
| 1149 | |
| 1150 | if (dev_routes && !cmd->ld->developer) |
| 1151 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1152 | "dev-routes requires --developer"); |
| 1153 | |
| 1154 | if (strlen(info->label->s) > inv_max_label_len) { |
| 1155 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1156 | "Label '%s' over %zu bytes", info->label->s, inv_max_label_len); |
| 1157 | } |
| 1158 | |
| 1159 | if (strlen(desc_val) > BOLT11_FIELD_BYTE_LIMIT && !*hashonly) { |
| 1160 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1161 | "Description greater than %d bytes " |
| 1162 | "invalid " |
| 1163 | "(description length %zu)", |
| 1164 | BOLT11_FIELD_BYTE_LIMIT, |
| 1165 | strlen(desc_val)); |
| 1166 | } |
| 1167 |
nothing calls this directly
no test coverage detected