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

Function invoice_decode

common/bolt12.c:545–622  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

543}
544
545struct tlv_invoice *invoice_decode(const tal_t *ctx,
546 const char *b12, size_t b12len,
547 const struct feature_set *our_features,
548 const struct chainparams *must_be_chain,
549 const char **fail)
550{
551 struct tlv_invoice *invoice;
552
553 invoice = invoice_decode_minimal(ctx, b12, b12len, our_features,
554 must_be_chain, fail);
555 if (!invoice)
556 return NULL;
557
558 *fail = check_signature(ctx, invoice->fields,
559 "invoice", "signature",
560 invoice->invoice_node_id,
561 invoice->signature);
562 if (*fail)
563 return tal_free(invoice);
564
565 /* BOLT #12:
566 * A reader of an invoice:
567 * - MUST reject the invoice if `invoice_amount` is not present.
568 * - MUST reject the invoice if `invoice_created_at` is not present.
569 * - MUST reject the invoice if `invoice_payment_hash` is not present.
570 * - MUST reject the invoice if `invoice_node_id` is not present.
571 */
572 if (!invoice->invoice_amount) {
573 *fail = tal_strdup(ctx, "missing invoice_amount");
574 return tal_free(invoice);
575 }
576 if (!invoice->invoice_created_at) {
577 *fail = tal_strdup(ctx, "missing invoice_created_at");
578 return tal_free(invoice);
579 }
580 if (!invoice->invoice_payment_hash) {
581 *fail = tal_strdup(ctx, "missing invoice_payment_hash");
582 return tal_free(invoice);
583 }
584 if (!invoice->invoice_node_id) {
585 *fail = tal_strdup(ctx, "missing invoicenode_id");
586 return tal_free(invoice);
587 }
588
589 /* BOLT #12:
590 * - MUST reject the invoice if `invoice_paths` is not present or is
591 * empty. */
592 if (tal_count(invoice->invoice_paths) == 0) {
593 *fail = tal_strdup(ctx, "missing/empty invoice_paths");
594 return tal_free(invoice);
595 }
596
597 /* BOLT #12:
598 * - MUST reject the invoice if `num_hops` is 0 in any
599 * `blinded_path` in `invoice_paths`.
600 */
601 for (size_t i = 0; i < tal_count(invoice->invoice_paths); i++) {
602 if (tal_count(invoice->invoice_paths[i]->path) != 0)

Callers 15

json_injectpaymentonionFunction · 0.85
json_listsendpaysFunction · 0.85
prev_paymentFunction · 0.85
check_inv_conditionFunction · 0.85
json_add_invoice_fieldsFunction · 0.85
json_listinvoicesFunction · 0.85
runFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
prev_invoice_doneFunction · 0.85
json_payFunction · 0.85
createinvoice_doneFunction · 0.85

Calls 3

invoice_decode_minimalFunction · 0.85
check_signatureFunction · 0.85
tal_freeFunction · 0.85

Tested by 2

mainFunction · 0.68
mainFunction · 0.68