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

Function json_createinvoicerequest

lightningd/offer.c:467–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

465}
466
467static struct command_result *json_createinvoicerequest(struct command *cmd,
468 const char *buffer,
469 const jsmntok_t *obj,
470 const jsmntok_t *params)
471{
472 struct tlv_invoice_request *invreq;
473 struct json_escape *label;
474 struct json_stream *response;
475 u64 *prev_basetime = NULL;
476 struct sha256 merkle;
477 bool *save, *single_use;
478 enum offer_status status;
479 struct sha256 invreq_id;
480 const char *b12str;
481 const u8 *tweak;
482
483 if (!param_check(cmd, buffer, params,
484 p_req("bolt12", param_b12_invreq, &invreq),
485 p_req("savetodb", param_bool, &save),
486 p_opt("recurrence_label", param_label, &label),
487 p_opt_def("single_use", param_bool, &single_use, true),
488 NULL))
489 return command_param_failed();
490
491 if (*single_use)
492 status = OFFER_SINGLE_USE_UNUSED;
493 else
494 status = OFFER_MULTIPLE_USE_UNUSED;
495
496 /* If it's a recurring payment, we look for previous to copy basetime */
497 if (invreq->invreq_recurrence_counter) {
498 if (!label)
499 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
500 "Need payment label for recurring payments");
501
502 if (*invreq->invreq_recurrence_counter != 0) {
503 struct command_result *err
504 = prev_payment(cmd, label, invreq,
505 &prev_basetime);
506 if (err)
507 return err;
508 }
509 }
510
511 /* If the payer_id is not our node id, we sanity check that it
512 * correctly maps from invreq_metadata */
513 if (!pubkey_eq(invreq->invreq_payer_id, &cmd->ld->our_pubkey)) {
514 struct pubkey expected;
515 if (!payer_key(cmd->ld,
516 invreq->invreq_metadata,
517 tal_bytelen(invreq->invreq_metadata),
518 &expected)) {
519 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
520 "Invalid tweak");
521 }
522 if (!pubkey_eq(invreq->invreq_payer_id, &expected)) {
523 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
524 "payer_id did not match invreq_metadata derivation %s",

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
prev_paymentFunction · 0.85
tal_bytelenFunction · 0.85
fmt_pubkeyFunction · 0.85
hsm_sign_b12Function · 0.85
invrequest_encodeFunction · 0.85
invreq_invreq_idFunction · 0.85
json_populate_invreqFunction · 0.85
json_add_u64Function · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70

Tested by

no test coverage detected