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

Function invoice_decode

common/bolt12.c:828–905  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

826}
827
828struct tlv_invoice *invoice_decode(const tal_t *ctx,
829 const char *b12, size_t b12len,
830 const struct feature_set *our_features,
831 const struct chainparams *must_be_chain,
832 const char **fail)
833{
834 struct tlv_invoice *invoice;
835
836 invoice = invoice_decode_minimal(ctx, b12, b12len, our_features,
837 must_be_chain, fail);
838 if (!invoice)
839 return NULL;
840
841 *fail = check_signature(ctx, invoice->fields,
842 "invoice", "signature",
843 invoice->invoice_node_id,
844 invoice->signature);
845 if (*fail)
846 return tal_free(invoice);
847
848 /* BOLT #12:
849 * A reader of an invoice:
850 * - MUST reject the invoice if `invoice_amount` is not present.
851 * - MUST reject the invoice if `invoice_created_at` is not present.
852 * - MUST reject the invoice if `invoice_payment_hash` is not present.
853 * - MUST reject the invoice if `invoice_node_id` is not present.
854 */
855 if (!invoice->invoice_amount) {
856 *fail = tal_strdup(ctx, "missing invoice_amount");
857 return tal_free(invoice);
858 }
859 if (!invoice->invoice_created_at) {
860 *fail = tal_strdup(ctx, "missing invoice_created_at");
861 return tal_free(invoice);
862 }
863 if (!invoice->invoice_payment_hash) {
864 *fail = tal_strdup(ctx, "missing invoice_payment_hash");
865 return tal_free(invoice);
866 }
867 if (!invoice->invoice_node_id) {
868 *fail = tal_strdup(ctx, "missing invoicenode_id");
869 return tal_free(invoice);
870 }
871
872 /* BOLT #12:
873 * - MUST reject the invoice if `invoice_paths` is not present or is
874 * empty. */
875 if (tal_count(invoice->invoice_paths) == 0) {
876 *fail = tal_strdup(ctx, "missing/empty invoice_paths");
877 return tal_free(invoice);
878 }
879
880 /* BOLT #12:
881 * - MUST reject the invoice if `num_hops` is 0 in any
882 * `blinded_path` in `invoice_paths`.
883 */
884 for (size_t i = 0; i < tal_count(invoice->invoice_paths); i++) {
885 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