| 1274 | AUTODATA(json_command, &invoice_command); |
| 1275 | |
| 1276 | static void json_add_invoices(struct json_stream *response, |
| 1277 | struct wallet *wallet, |
| 1278 | const struct json_escape *label, |
| 1279 | const struct sha256 *payment_hash, |
| 1280 | const struct sha256 *local_offer_id, |
| 1281 | const enum wait_index *listindex, |
| 1282 | u64 liststart, |
| 1283 | const u32 *listlimit) |
| 1284 | { |
| 1285 | const struct invoice_details *details; |
| 1286 | u64 inv_dbid; |
| 1287 | |
| 1288 | /* Don't iterate entire db if we're just after one. */ |
| 1289 | if (label) { |
| 1290 | if (invoices_find_by_label(wallet->invoices, &inv_dbid, label)) { |
| 1291 | details = |
| 1292 | invoices_get_details(tmpctx, wallet->invoices, inv_dbid); |
| 1293 | json_add_invoice(response, NULL, details); |
| 1294 | } |
| 1295 | } else if (payment_hash != NULL) { |
| 1296 | if (invoices_find_by_rhash(wallet->invoices, &inv_dbid, |
| 1297 | payment_hash)) { |
| 1298 | details = |
| 1299 | invoices_get_details(tmpctx, wallet->invoices, inv_dbid); |
| 1300 | json_add_invoice(response, NULL, details); |
| 1301 | } |
| 1302 | } else { |
| 1303 | struct db_stmt *stmt; |
| 1304 | |
| 1305 | for (stmt = invoices_first(wallet->invoices, |
| 1306 | listindex, liststart, listlimit, |
| 1307 | &inv_dbid); |
| 1308 | stmt; |
| 1309 | stmt = invoices_next(wallet->invoices, stmt, &inv_dbid)) { |
| 1310 | details = invoices_get_details(tmpctx, |
| 1311 | wallet->invoices, inv_dbid); |
| 1312 | /* FIXME: db can filter this better! */ |
| 1313 | if (local_offer_id) { |
| 1314 | if (!details->local_offer_id |
| 1315 | || !sha256_eq(local_offer_id, |
| 1316 | details->local_offer_id)) |
| 1317 | continue; |
| 1318 | } |
| 1319 | json_add_invoice(response, NULL, details); |
| 1320 | } |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | static struct command_result *json_listinvoices(struct command *cmd, |
| 1325 | const char *buffer, |
no test coverage detected