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

Function json_add_invoices

lightningd/invoice.c:1276–1322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1274AUTODATA(json_command, &invoice_command);
1275
1276static 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
1324static struct command_result *json_listinvoices(struct command *cmd,
1325 const char *buffer,

Callers 1

json_listinvoicesFunction · 0.85

Calls 6

json_add_invoiceFunction · 0.85
invoices_find_by_labelFunction · 0.50
invoices_get_detailsFunction · 0.50
invoices_find_by_rhashFunction · 0.50
invoices_firstFunction · 0.50
invoices_nextFunction · 0.50

Tested by

no test coverage detected