Returns true if "fatal" error, otherwise just a normal error */
| 1144 | |
| 1145 | /* Returns true if "fatal" error, otherwise just a normal error */ |
| 1146 | static char *fetch_out_desc_invstr(const tal_t *ctx, const char *buf, |
| 1147 | const jsmntok_t *tok, char **err) |
| 1148 | { |
| 1149 | char *bolt, *desc, *fail; |
| 1150 | |
| 1151 | /* It's a bolt11! Parse it out to a desc */ |
| 1152 | if (!json_scan(ctx, buf, tok, "{bolt11:%}", |
| 1153 | JSON_SCAN_TAL(ctx, json_strdup, &bolt))) { |
| 1154 | struct bolt11 *bolt11; |
| 1155 | u5 *sigdata; |
| 1156 | struct sha256 hash; |
| 1157 | bool have_n; |
| 1158 | |
| 1159 | bolt11 = bolt11_decode_nosig(ctx, bolt, |
| 1160 | /* No desc/features/chain checks */ |
| 1161 | NULL, NULL, NULL, |
| 1162 | &hash, &sigdata, &have_n, |
| 1163 | &fail); |
| 1164 | |
| 1165 | if (bolt11) { |
| 1166 | if (bolt11->description) |
| 1167 | desc = tal_strdup(ctx, bolt11->description); |
| 1168 | else if (bolt11->description_hash) |
| 1169 | desc = tal_fmt(ctx, "%s", |
| 1170 | type_to_string(ctx, |
| 1171 | struct sha256, |
| 1172 | bolt11->description_hash)); |
| 1173 | else |
| 1174 | desc = NULL; |
| 1175 | } else { |
| 1176 | *err = tal_fmt(ctx, "failed to parse bolt11 %s: %s", |
| 1177 | bolt, fail); |
| 1178 | return NULL; |
| 1179 | } |
| 1180 | } else if (!json_scan(ctx, buf, tok, "{bolt12:%}", |
| 1181 | JSON_SCAN_TAL(ctx, json_strdup, &bolt))) { |
| 1182 | struct tlv_invoice *bolt12; |
| 1183 | |
| 1184 | bolt12 = invoice_decode_nosig(ctx, bolt, strlen(bolt), |
| 1185 | /* No features/chain checks */ |
| 1186 | NULL, NULL, |
| 1187 | &fail); |
| 1188 | if (!bolt12) { |
| 1189 | *err = tal_fmt(ctx, "failed to parse" |
| 1190 | " bolt12 %s: %s", |
| 1191 | bolt, fail); |
| 1192 | return NULL; |
| 1193 | } |
| 1194 | |
| 1195 | if (bolt12->description) |
| 1196 | desc = tal_strndup(ctx, |
| 1197 | cast_signed(char *, bolt12->description), |
| 1198 | tal_bytelen(bolt12->description)); |
| 1199 | else |
| 1200 | desc = NULL; |
| 1201 | } else |
| 1202 | desc = NULL; |
| 1203 |
no test coverage detected