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