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

Function json_offer

plugins/offers_offer.c:315–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313}
314
315struct command_result *json_offer(struct command *cmd,
316 const char *buffer,
317 const jsmntok_t *params)
318{
319 const char *desc, *issuer;
320 struct tlv_offer *offer;
321 struct offer_info *offinfo = tal(cmd, struct offer_info);
322
323 offinfo->offer = offer = tlv_offer_new(offinfo);
324
325 if (!param(cmd, buffer, params,
326 p_req("amount", param_amount, offer),
327 p_req("description", param_escaped_string, &desc),
328 p_opt("issuer", param_escaped_string, &issuer),
329 p_opt("label", param_escaped_string, &offinfo->label),
330 p_opt("quantity_min", param_u64, &offer->quantity_min),
331 p_opt("quantity_max", param_u64, &offer->quantity_max),
332 p_opt("absolute_expiry", param_u64, &offer->absolute_expiry),
333 p_opt("recurrence", param_recurrence, &offer->recurrence),
334 p_opt("recurrence_base",
335 param_recurrence_base,
336 &offer->recurrence_base),
337 p_opt("recurrence_paywindow",
338 param_recurrence_paywindow,
339 &offer->recurrence_paywindow),
340 p_opt("recurrence_limit",
341 param_number,
342 &offer->recurrence_limit),
343 p_opt_def("single_use", param_bool,
344 &offinfo->single_use, false),
345 /* FIXME: hints support! */
346 NULL))
347 return command_param_failed();
348
349 if (!offers_enabled)
350 return command_fail(cmd, LIGHTNINGD,
351 "experimental-offers not enabled");
352
353 /* BOLT-offers #12:
354 * - MUST NOT set `quantity_min` or `quantity_max` less than 1.
355 */
356 if (offer->quantity_min && *offer->quantity_min < 1)
357 return command_fail_badparam(cmd, "quantity_min",
358 buffer, params,
359 "must be >= 1");
360 if (offer->quantity_max && *offer->quantity_max < 1)
361 return command_fail_badparam(cmd, "quantity_max",
362 buffer, params,
363 "must be >= 1");
364 /* BOLT-offers #12:
365 * - if both:
366 * - MUST set `quantity_min` less than or equal to `quantity_max`.
367 */
368 if (offer->quantity_min && offer->quantity_max) {
369 if (*offer->quantity_min > *offer->quantity_max)
370 return command_fail_badparam(cmd, "quantity_min",
371 buffer, params,
372 "must be <= quantity_max");

Callers

nothing calls this directly

Calls 9

command_fail_badparamFunction · 0.85
tal_bytelenFunction · 0.85
create_offerFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
send_outreqFunction · 0.70
paramFunction · 0.50
json_add_u32Function · 0.50
json_add_stringnFunction · 0.50

Tested by

no test coverage detected