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

Function json_delinvoice

lightningd/invoice.c:1417–1494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1415AUTODATA(json_command, &listinvoices_command);
1416
1417static struct command_result *json_delinvoice(struct command *cmd,
1418 const char *buffer,
1419 const jsmntok_t *obj UNNEEDED,
1420 const jsmntok_t *params)
1421{
1422 u64 inv_dbid;
1423 struct invoice_details *details;
1424 struct json_stream *response;
1425 const char *status, *actual_status;
1426 struct json_escape *label;
1427 struct wallet *wallet = cmd->ld->wallet;
1428 bool *deldesc;
1429
1430 if (!param_check(cmd, buffer, params,
1431 p_req("label", param_label, &label),
1432 p_req("status", param_string, &status),
1433 p_opt_def("desconly", param_bool, &deldesc, false),
1434 NULL))
1435 return command_param_failed();
1436
1437 if (!invoices_find_by_label(wallet->invoices, &inv_dbid, label)) {
1438 return command_fail(cmd, INVOICE_NOT_FOUND, "Unknown invoice");
1439 }
1440
1441 details = invoices_get_details(cmd, cmd->ld->wallet->invoices, inv_dbid);
1442
1443 /* This is time-sensitive, so only call once; otherwise error msg
1444 * might not make sense if it changed! */
1445 actual_status = invoice_status_str(details->state);
1446 if (!streq(actual_status, status)) {
1447 struct json_stream *js;
1448 js = json_stream_fail(cmd, INVOICE_STATUS_UNEXPECTED,
1449 tal_fmt(tmpctx,
1450 "Invoice status is %s not %s",
1451 actual_status, status));
1452 json_add_string(js, "current_status", actual_status);
1453 json_add_string(js, "expected_status", status);
1454 json_object_end(js);
1455 return command_failed(cmd, js);
1456 }
1457
1458 if (*deldesc) {
1459 if (!details->description)
1460 return command_fail(cmd, INVOICE_NO_DESCRIPTION,
1461 "Invoice description already removed");
1462
1463 if (command_check_only(cmd))
1464 return command_check_done(cmd);
1465
1466 if (!invoices_delete_description(wallet->invoices, inv_dbid,
1467 details->label, details->description)) {
1468 log_broken(cmd->ld->log,
1469 "Error attempting to delete description of invoice %"PRIu64,
1470 inv_dbid);
1471 /* FIXME: allocate a generic DATABASE_ERROR code. */
1472 return command_fail(cmd, LIGHTNINGD, "Database error");
1473 }
1474 details->description = tal_free(details->description);

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
invoice_status_strFunction · 0.85
json_object_endFunction · 0.85
tal_freeFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
json_stream_failFunction · 0.70
command_failedFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70
json_stream_successFunction · 0.70
json_add_invoice_fieldsFunction · 0.70

Tested by

no test coverage detected