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

Function json_delpay

lightningd/pay.c:2326–2396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

param_checkFunction · 0.85
payments_by_hashFunction · 0.85
fmt_sha256Function · 0.85
payments_nextFunction · 0.85
payment_get_detailsFunction · 0.85
payment_status_to_stringFunction · 0.85
wallet_payment_deleteFunction · 0.85
json_array_startFunction · 0.85
json_object_startFunction · 0.85
json_add_payment_fieldsFunction · 0.85
json_object_endFunction · 0.85
json_array_endFunction · 0.85

Tested by

no test coverage detected