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

Function json_invoice

lightningd/invoice.c:1112–1281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1110}
1111
1112static 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);

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
log_infoClass · 0.85
scriptpubkey_p2trFunction · 0.85
invoice_secretFunction · 0.85
new_bolt11Function · 0.85
clock_timeFunction · 0.85
unpack_routesFunction · 0.85
invoice_completeFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70

Tested by

no test coverage detected