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

Function json_delinvoice

lightningd/invoice.c:1404–1481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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