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

Function check_inv_condition

lightningd/runes.c:801–852  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

799}
800
801static const char *check_inv_condition(const tal_t *ctx,
802 const struct rune_altern *alt,
803 struct cond_info *cinfo)
804{
805 const char *invfield = alt->fieldname + strlen("pinv");
806 const char *param;
807 const char *b11fail, *b12fail;
808 const struct bolt11 *b11;
809 const struct tlv_invoice *b12;
810 enum invoice_field invf;
811 const jsmntok_t *ptok;
812 const char *invstr;
813
814 param = match_inv_condition(tmpctx, invfield, &invf);
815 if (!param)
816 return tal_fmt(ctx, "Unknown invoice field %s", invfield);
817
818 /* strmap contains pname<param> */
819 ptok = strmap_get(&cinfo->cached_params,
820 tal_fmt(tmpctx, "pname%s", param));
821 if (!ptok)
822 return tal_fmt(ctx, "Unknown invoice parameter %s", param);
823 if (ptok == &ambiguous_param)
824 return tal_fmt(ctx, "Ambiguous invoice parameter %s", param);
825
826 invstr = json_strdup(tmpctx, cinfo->buf, ptok);
827 if (strstarts(invstr, "lightning:") || strstarts(invstr, "LIGHTNING:"))
828 invstr += strlen("lightning:");
829
830 b11 = bolt11_decode(tmpctx,
831 invstr,
832 NULL,
833 NULL,
834 NULL,
835 &b11fail);
836 if (b11)
837 return check_bolt11_condition(ctx, alt, b11, invf);
838
839 b12 = invoice_decode(tmpctx,
840 invstr, strlen(invstr),
841 NULL,
842 NULL,
843 &b12fail);
844 if (b12)
845 return check_bolt12_condition(ctx, alt, b12, invf);
846
847 /* If it looks like BOLT11, use that fail msg (it's probably
848 * more informative!) */
849 if (strstarts(invstr, "lni"))
850 return tal_fmt(ctx, "Invalid invoice: %s", b12fail);
851 return tal_fmt(ctx, "Invalid invoice: %s", b11fail);
852}
853
854static const char *check_condition(const tal_t *ctx,
855 const struct rune *rune,

Callers 1

check_conditionFunction · 0.85

Calls 6

match_inv_conditionFunction · 0.85
bolt11_decodeFunction · 0.85
check_bolt11_conditionFunction · 0.85
invoice_decodeFunction · 0.85
check_bolt12_conditionFunction · 0.85
json_strdupFunction · 0.50

Tested by

no test coverage detected