| 1322 | } |
| 1323 | |
| 1324 | static struct command_result *json_listinvoices(struct command *cmd, |
| 1325 | const char *buffer, |
| 1326 | const jsmntok_t *obj UNNEEDED, |
| 1327 | const jsmntok_t *params) |
| 1328 | { |
| 1329 | struct json_escape *label; |
| 1330 | struct json_stream *response; |
| 1331 | struct wallet *wallet = cmd->ld->wallet; |
| 1332 | const char *invstring; |
| 1333 | struct sha256 *payment_hash, *offer_id; |
| 1334 | enum wait_index *listindex; |
| 1335 | u64 *liststart; |
| 1336 | u32 *listlimit; |
| 1337 | const char *fail; |
| 1338 | |
| 1339 | if (!param_check(cmd, buffer, params, |
| 1340 | p_opt("label", param_label, &label), |
| 1341 | p_opt("invstring", param_invstring, &invstring), |
| 1342 | p_opt("payment_hash", param_sha256, &payment_hash), |
| 1343 | p_opt("offer_id", param_sha256, &offer_id), |
| 1344 | p_opt("index", param_index, &listindex), |
| 1345 | p_opt_def("start", param_u64, &liststart, 0), |
| 1346 | p_opt("limit", param_u32, &listlimit), |
| 1347 | NULL)) |
| 1348 | return command_param_failed(); |
| 1349 | |
| 1350 | /* Yeah, I wasn't sure about this style either. It's curt though! */ |
| 1351 | if (!!label + !!invstring + !!payment_hash + !!offer_id > 1) { |
| 1352 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1353 | "Can only specify one of" |
| 1354 | " {label}, {invstring}, {payment_hash}" |
| 1355 | " or {offer_id}"); |
| 1356 | } |
| 1357 | if (*liststart != 0 && !listindex) { |
| 1358 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1359 | "Can only specify {start} with {index}"); |
| 1360 | } |
| 1361 | if (listlimit && !listindex) { |
| 1362 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1363 | "Can only specify {limit} with {index}"); |
| 1364 | } |
| 1365 | |
| 1366 | /* Extract the payment_hash from the invoice. */ |
| 1367 | if (invstring != NULL) { |
| 1368 | struct bolt11 *b11; |
| 1369 | b11 = bolt11_decode(cmd, invstring, cmd->ld->our_features, NULL, |
| 1370 | NULL, &fail); |
| 1371 | if (b11) |
| 1372 | payment_hash = &b11->payment_hash; |
| 1373 | else { |
| 1374 | struct tlv_invoice *b12 |
| 1375 | = invoice_decode(tmpctx, invstring, |
| 1376 | strlen(invstring), |
| 1377 | cmd->ld->our_features, NULL, |
| 1378 | &fail); |
| 1379 | if (!b12 || !b12->invoice_payment_hash) { |
| 1380 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1381 | "Invalid invstring"); |
nothing calls this directly
no test coverage detected