| 1385 | AUTODATA(json_command, &listinvoices_command); |
| 1386 | |
| 1387 | static struct command_result *json_delinvoice(struct command *cmd, |
| 1388 | const char *buffer, |
| 1389 | const jsmntok_t *obj UNNEEDED, |
| 1390 | const jsmntok_t *params) |
| 1391 | { |
| 1392 | struct invoice i; |
| 1393 | struct invoice_details *details; |
| 1394 | struct json_stream *response; |
| 1395 | const char *status, *actual_status; |
| 1396 | struct json_escape *label; |
| 1397 | struct wallet *wallet = cmd->ld->wallet; |
| 1398 | bool *deldesc; |
| 1399 | |
| 1400 | if (!param(cmd, buffer, params, |
| 1401 | p_req("label", param_label, &label), |
| 1402 | p_req("status", param_string, &status), |
| 1403 | p_opt_def("desconly", param_bool, &deldesc, false), |
| 1404 | NULL)) |
| 1405 | return command_param_failed(); |
| 1406 | |
| 1407 | if (!wallet_invoice_find_by_label(wallet, &i, label)) { |
| 1408 | return command_fail(cmd, INVOICE_NOT_FOUND, "Unknown invoice"); |
| 1409 | } |
| 1410 | |
| 1411 | details = wallet_invoice_details(cmd, cmd->ld->wallet, i); |
| 1412 | |
| 1413 | /* This is time-sensitive, so only call once; otherwise error msg |
| 1414 | * might not make sense if it changed! */ |
| 1415 | actual_status = invoice_status_str(details); |
| 1416 | if (!streq(actual_status, status)) { |
| 1417 | struct json_stream *js; |
| 1418 | js = json_stream_fail(cmd, INVOICE_STATUS_UNEXPECTED, |
| 1419 | tal_fmt(tmpctx, |
| 1420 | "Invoice status is %s not %s", |
| 1421 | actual_status, status)); |
| 1422 | json_add_string(js, "current_status", actual_status); |
| 1423 | json_add_string(js, "expected_status", status); |
| 1424 | json_object_end(js); |
| 1425 | return command_failed(cmd, js); |
| 1426 | } |
| 1427 | |
| 1428 | if (*deldesc) { |
| 1429 | if (!details->description) |
| 1430 | return command_fail(cmd, INVOICE_NO_DESCRIPTION, |
| 1431 | "Invoice description already removed"); |
| 1432 | |
| 1433 | if (!wallet_invoice_delete_description(wallet, i)) { |
| 1434 | log_broken(cmd->ld->log, |
| 1435 | "Error attempting to delete description of invoice %"PRIu64, |
| 1436 | i.id); |
| 1437 | /* FIXME: allocate a generic DATABASE_ERROR code. */ |
| 1438 | return command_fail(cmd, LIGHTNINGD, "Database error"); |
| 1439 | } |
| 1440 | details->description = tal_free(details->description); |
| 1441 | } else { |
| 1442 | if (!wallet_invoice_delete(wallet, i)) { |
| 1443 | log_broken(cmd->ld->log, |
| 1444 | "Error attempting to remove invoice %"PRIu64, |
nothing calls this directly
no test coverage detected