| 1110 | } |
| 1111 | |
| 1112 | static struct command_result *json_invoice(struct command *cmd, |
| 1113 | const char *buffer, |
| 1114 | const jsmntok_t *obj UNNEEDED, |
| 1115 | const jsmntok_t *params) |
| 1116 | { |
| 1117 | const jsmntok_t *fallbacks; |
| 1118 | struct amount_msat *msatoshi_val; |
| 1119 | struct invoice_info *info; |
| 1120 | const char *desc_val; |
| 1121 | const u8 **fallback_scripts = NULL; |
| 1122 | u64 *expiry; |
| 1123 | struct sha256 rhash; |
| 1124 | struct secret payment_secret; |
| 1125 | struct preimage *preimage; |
| 1126 | u32 *cltv; |
| 1127 | struct jsonrpc_request *req; |
| 1128 | struct plugin *plugin; |
| 1129 | bool *hashonly; |
| 1130 | const size_t inv_max_label_len = 128; |
| 1131 | const jsmntok_t *dev_routes; |
| 1132 | |
| 1133 | info = tal(cmd, struct invoice_info); |
| 1134 | info->cmd = cmd; |
| 1135 | |
| 1136 | if (!param_check(cmd, buffer, params, |
| 1137 | p_req("amount_msat", param_positive_msat_or_any, &msatoshi_val), |
| 1138 | p_req("label", param_label, &info->label), |
| 1139 | p_req("description", param_escaped_string, &desc_val), |
| 1140 | p_opt_def("expiry", param_u64, &expiry, 3600*24*7), |
| 1141 | p_opt("fallbacks", param_array, &fallbacks), |
| 1142 | p_opt("preimage", param_preimage, &preimage), |
| 1143 | p_opt("exposeprivatechannels", param_chanhints, |
| 1144 | &info->chanhints), |
| 1145 | p_opt_def("cltv", param_number, &cltv, |
| 1146 | cmd->ld->config.cltv_final), |
| 1147 | p_opt_def("deschashonly", param_bool, &hashonly, false), |
| 1148 | p_opt("dev-routes", param_array, &dev_routes), |
| 1149 | NULL)) |
| 1150 | return command_param_failed(); |
| 1151 | |
| 1152 | if (dev_routes && !cmd->ld->developer) |
| 1153 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1154 | "dev-routes requires --developer"); |
| 1155 | |
| 1156 | /* Two hard limits on how far in the future an invoice can expire: |
| 1157 | * push_varlen_field() can only encode up to 60 bits (larger values |
| 1158 | * abort the daemon in bolt11_encode()), and the invoice expiration |
| 1159 | * timer overflows its u64 nanosecond-based grain count far below |
| 1160 | * that, leaving the expiry check looping forever. 2^32 seconds |
| 1161 | * (~136 years) keeps a wide margin under both. */ |
| 1162 | if (*expiry >= (u64)1 << 32) |
| 1163 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1164 | "expiry must be below 2^32 seconds" |
| 1165 | " (~136 years)"); |
| 1166 | |
| 1167 | if (strlen(info->label->s) > inv_max_label_len) { |
| 1168 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1169 | "Label '%s' over %zu bytes", info->label->s, inv_max_label_len); |
nothing calls this directly
no test coverage detected