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

Function json_offerout

plugins/offers_offer.c:428–483  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

426}
427
428struct command_result *json_offerout(struct command *cmd,
429 const char *buffer,
430 const jsmntok_t *params)
431{
432 const char *desc, *issuer, *label;
433 struct tlv_offer *offer;
434 struct out_req *req;
435
436 offer = tlv_offer_new(cmd);
437
438 if (!param(cmd, buffer, params,
439 p_req("amount", param_msat_or_any, offer),
440 p_req("description", param_escaped_string, &desc),
441 p_opt("issuer", param_escaped_string, &issuer),
442 p_opt("label", param_escaped_string, &label),
443 p_opt("absolute_expiry", param_u64, &offer->absolute_expiry),
444 p_opt("refund_for", param_invoice_payment_hash, &offer->refund_for),
445 /* FIXME: hints support! */
446 NULL))
447 return command_param_failed();
448
449 if (!offers_enabled)
450 return command_fail(cmd, LIGHTNINGD,
451 "experimental-offers not enabled");
452
453 offer->send_invoice = tal(offer, struct tlv_offer_send_invoice);
454
455 /* BOLT-offers #12:
456 *
457 * - if the chain for the invoice is not solely bitcoin:
458 * - MUST specify `chains` the offer is valid for.
459 * - otherwise:
460 * - the bitcoin chain is implied as the first and only entry.
461 */
462 if (!streq(chainparams->network_name, "bitcoin")) {
463 offer->chains = tal_arr(offer, struct bitcoin_blkid, 1);
464 offer->chains[0] = chainparams->genesis_blockhash;
465 }
466
467 offer->description = tal_dup_arr(offer, char, desc, strlen(desc), 0);
468 if (issuer)
469 offer->issuer = tal_dup_arr(offer, char,
470 issuer, strlen(issuer), 0);
471
472 offer->node_id = tal_dup(offer, struct point32, &id);
473
474 req = jsonrpc_request_start(cmd->plugin, cmd, "createoffer",
475 check_result, forward_error,
476 offer);
477 json_add_string(req->js, "bolt12", offer_encode(tmpctx, offer));
478 if (label)
479 json_add_string(req->js, "label", label);
480 json_add_bool(req->js, "single_use", true);
481
482 return send_outreq(cmd->plugin, req);
483}
484

Callers

nothing calls this directly

Calls 7

offer_encodeFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
send_outreqFunction · 0.70
paramFunction · 0.50
json_add_stringFunction · 0.50
json_add_boolFunction · 0.50

Tested by

no test coverage detected