| 2321 | } |
| 2322 | |
| 2323 | static struct command_result *json_delpay(struct command *cmd, |
| 2324 | const char *buffer, |
| 2325 | const jsmntok_t *obj UNNEEDED, |
| 2326 | const jsmntok_t *params) |
| 2327 | { |
| 2328 | const enum payment_status *found_status = NULL; |
| 2329 | struct json_stream *response; |
| 2330 | const struct wallet_payment **payments; |
| 2331 | enum payment_status *status; |
| 2332 | struct sha256 *payment_hash; |
| 2333 | u64 *groupid, *partid; |
| 2334 | struct db_stmt *stmt; |
| 2335 | |
| 2336 | if (!param_check(cmd, buffer, params, |
| 2337 | p_req("payment_hash", param_sha256, &payment_hash), |
| 2338 | p_req("status", param_payment_status_nopending, &status), |
| 2339 | p_opt("partid", param_u64, &partid), |
| 2340 | p_opt("groupid", param_u64, &groupid), |
| 2341 | NULL)) |
| 2342 | return command_param_failed(); |
| 2343 | |
| 2344 | if ((partid != NULL) != (groupid != NULL)) |
| 2345 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2346 | "Must set both partid and groupid, or neither"); |
| 2347 | |
| 2348 | stmt = payments_by_hash(cmd->ld->wallet, payment_hash); |
| 2349 | if (!stmt) |
| 2350 | return command_fail(cmd, PAY_NO_SUCH_PAYMENT, "Unknown payment with payment_hash: %s", |
| 2351 | fmt_sha256(tmpctx, payment_hash)); |
| 2352 | |
| 2353 | payments = tal_arr(cmd, const struct wallet_payment *, 0); |
| 2354 | for (; stmt; stmt = payments_next(cmd->ld->wallet, stmt)) { |
| 2355 | struct wallet_payment *payment; |
| 2356 | payment = payment_get_details(payments, stmt); |
| 2357 | if (groupid && payment->groupid != *groupid) |
| 2358 | continue; |
| 2359 | if (partid && payment->partid != *partid) |
| 2360 | continue; |
| 2361 | |
| 2362 | if (payment->status == *status) |
| 2363 | tal_arr_expand(&payments, payment); |
| 2364 | else |
| 2365 | found_status = &payment->status; |
| 2366 | } |
| 2367 | |
| 2368 | if (tal_count(payments) == 0) { |
| 2369 | if (found_status) |
| 2370 | return command_fail(cmd, PAY_NO_SUCH_PAYMENT, "Payment with hash %s has %s status but it different from the one provided %s", |
| 2371 | fmt_sha256(tmpctx, payment_hash), |
| 2372 | payment_status_to_string(*found_status), |
| 2373 | payment_status_to_string(*status)); |
| 2374 | |
| 2375 | return command_fail(cmd, PAY_NO_SUCH_PAYMENT, |
| 2376 | "No payment for that payment_hash with that partid and groupid"); |
| 2377 | } |
| 2378 | |
| 2379 | if (command_check_only(cmd)) |
| 2380 | return command_check_done(cmd); |
nothing calls this directly
no test coverage detected