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

Function json_createinvoicerequest

lightningd/offer.c:417–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415}
416
417static struct command_result *json_createinvoicerequest(struct command *cmd,
418 const char *buffer,
419 const jsmntok_t *obj,
420 const jsmntok_t *params)
421{
422 struct tlv_invoice_request *invreq;
423 const char *label;
424 struct json_stream *response;
425 u64 *prev_basetime = NULL;
426 struct sha256 merkle;
427
428 if (!param(cmd, buffer, params,
429 p_req("bolt12", param_b12_invreq, &invreq),
430 p_opt("recurrence_label", param_escaped_string, &label),
431 NULL))
432 return command_param_failed();
433
434 if (invreq->recurrence_counter) {
435 if (!label)
436 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
437 "Need payment label for recurring payments");
438
439 if (*invreq->recurrence_counter != 0) {
440 struct command_result *err
441 = prev_payment(cmd, label, invreq,
442 &prev_basetime);
443 if (err)
444 return err;
445 }
446 }
447
448 if (!invreq->payer_info) {
449 /* BOLT-offers #12:
450 * `payer_info` might typically contain information about the
451 * derivation of the `payer_key`. This should not leak any
452 * information (such as using a simple BIP-32 derivation
453 * path); a valid system might be for a node to maintain a
454 * base payer key, and encode a 128-bit tweak here. The
455 * payer_key would be derived by tweaking the base key with
456 * SHA256(payer_base_pubkey || tweak).
457 */
458 invreq->payer_info = tal_arr(invreq, u8, 16);
459 randombytes_buf(invreq->payer_info,
460 tal_bytelen(invreq->payer_info));
461 }
462
463 invreq->payer_key = tal(invreq, struct point32);
464 if (!payer_key(cmd->ld,
465 invreq->payer_info, tal_bytelen(invreq->payer_info),
466 invreq->payer_key)) {
467 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
468 "Invalid tweak");
469 }
470
471 /* BOLT-offers #12:
472 * - MUST set `signature` `sig` as detailed in
473 * [Signature Calculation](#signature-calculation) using the `payer_key`.
474 */

Callers

nothing calls this directly

Calls 15

prev_paymentFunction · 0.85
tal_bytelenFunction · 0.85
payer_keyFunction · 0.85
hsm_sign_b12Function · 0.85
invrequest_encodeFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
json_stream_successFunction · 0.70
json_escapeClass · 0.70
command_successFunction · 0.70
paramFunction · 0.50
merkle_tlvFunction · 0.50

Tested by

no test coverage detected