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

Function check_inv_condition

lightningd/runes.c:770–819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

768}
769
770static const char *check_inv_condition(const tal_t *ctx,
771 const struct rune_altern *alt,
772 struct cond_info *cinfo)
773{
774 const char *invfield = alt->fieldname + strlen("pinv");
775 const char *param;
776 const char *b11fail, *b12fail;
777 const struct bolt11 *b11;
778 const struct tlv_invoice *b12;
779 enum invoice_field invf;
780 const jsmntok_t *ptok;
781 const char *invstr;
782
783 param = match_inv_condition(tmpctx, invfield, &invf);
784 if (!param)
785 return tal_fmt(ctx, "Unknown invoice field %s", invfield);
786
787 /* strmap contains pname<param> */
788 ptok = strmap_get(&cinfo->cached_params,
789 tal_fmt(tmpctx, "pname%s", param));
790 if (!ptok)
791 return tal_fmt(ctx, "Unknown invoice parameter %s", param);
792
793 invstr = json_strdup(tmpctx, cinfo->buf, ptok);
794 if (strstarts(invstr, "lightning:") || strstarts(invstr, "LIGHTNING:"))
795 invstr += strlen("lightning:");
796
797 b11 = bolt11_decode(tmpctx,
798 invstr,
799 NULL,
800 NULL,
801 NULL,
802 &b11fail);
803 if (b11)
804 return check_bolt11_condition(ctx, alt, b11, invf);
805
806 b12 = invoice_decode(tmpctx,
807 invstr, strlen(invstr),
808 NULL,
809 NULL,
810 &b12fail);
811 if (b12)
812 return check_bolt12_condition(ctx, alt, b12, invf);
813
814 /* If it looks like BOLT11, use that fail msg (it's probably
815 * more informative!) */
816 if (strstarts(invstr, "lni"))
817 return tal_fmt(ctx, "Invalid invoice: %s", b12fail);
818 return tal_fmt(ctx, "Invalid invoice: %s", b11fail);
819}
820
821static const char *check_condition(const tal_t *ctx,
822 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