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

Function fetch_out_desc_invstr

plugins/bkpr/bookkeeper.c:1058–1118  ·  view source on GitHub ↗

Returns true if "fatal" error, otherwise just a normal error */

Source from the content-addressed store, hash-verified

1056
1057/* Returns true if "fatal" error, otherwise just a normal error */
1058static char *fetch_out_desc_invstr(const tal_t *ctx, const char *buf,
1059 const jsmntok_t *tok, char **err)
1060{
1061 char *bolt, *desc;
1062 const char *fail;
1063
1064 /* It's a bolt11! Parse it out to a desc */
1065 if (!json_scan(ctx, buf, tok, "{bolt11:%}",
1066 JSON_SCAN_TAL(ctx, json_strdup, &bolt))) {
1067 struct bolt11 *bolt11;
1068 const u5 *sigdata;
1069 struct sha256 hash;
1070 bool have_n;
1071
1072 bolt11 = bolt11_decode_nosig(ctx, bolt,
1073 /* No desc/features/chain checks */
1074 NULL, NULL, NULL,
1075 &hash, &sigdata, &have_n,
1076 &fail);
1077
1078 if (bolt11) {
1079 if (bolt11->description)
1080 desc = tal_strdup(ctx, bolt11->description);
1081 else if (bolt11->description_hash)
1082 desc = tal_fmt(ctx, "%s",
1083 fmt_sha256(ctx,
1084 bolt11->description_hash));
1085 else
1086 desc = NULL;
1087 } else {
1088 *err = tal_fmt(ctx, "failed to parse bolt11 %s: %s",
1089 bolt, fail);
1090 return NULL;
1091 }
1092 } else if (!json_scan(ctx, buf, tok, "{bolt12:%}",
1093 JSON_SCAN_TAL(ctx, json_strdup, &bolt))) {
1094 struct tlv_invoice *bolt12;
1095
1096 bolt12 = invoice_decode_minimal(ctx, bolt, strlen(bolt),
1097 /* No features/chain checks */
1098 NULL, NULL,
1099 &fail);
1100 if (!bolt12) {
1101 *err = tal_fmt(ctx, "failed to parse"
1102 " bolt12 %s: %s",
1103 bolt, fail);
1104 return NULL;
1105 }
1106
1107 if (bolt12->offer_description)
1108 desc = tal_strndup(ctx,
1109 cast_signed(char *, bolt12->offer_description),
1110 tal_bytelen(bolt12->offer_description));
1111 else
1112 desc = NULL;
1113 } else
1114 desc = NULL;
1115

Callers 2

listinvoices_doneFunction · 0.85
listsendpays_doneFunction · 0.85

Calls 5

bolt11_decode_nosigFunction · 0.85
fmt_sha256Function · 0.85
invoice_decode_minimalFunction · 0.85
tal_bytelenFunction · 0.85
json_scanFunction · 0.50

Tested by

no test coverage detected