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

Function payment_listsendpays_previous

plugins/pay.c:512–634  ·  view source on GitHub ↗

We are interested in any prior attempts to pay this payment_hash / * invoice so we can set the `groupid` correctly and ensure we don't * already have a pending payment running. We also collect the summary * about an eventual previous complete payment so we can return that * as a no-op. */

Source from the content-addressed store, hash-verified

510 * about an eventual previous complete payment so we can return that
511 * as a no-op. */
512static struct command_result *
513payment_listsendpays_previous(struct command *cmd,
514 const char *method,
515 const char *buf,
516 const jsmntok_t *result,
517 struct payment *p)
518{
519 size_t i;
520 const jsmntok_t *t, *arr, *err;
521 /* What was the groupid of an eventual previous attempt? */
522 u64 last_group = 0;
523 /* Do we have pending sendpays for the previous attempt? */
524 bool pending = false;
525
526 /* Group ID of the first pending payment, this will be the one
527 * who's result gets replayed if we end up suspending. */
528 u64 pending_group_id = 0;
529 /* Did a prior attempt succeed? */
530 bool completed = false;
531
532 /* Metadata for a complete payment, if one exists. */
533 struct json_stream *ret;
534 u32 parts = 0;
535 struct preimage preimage;
536 struct amount_msat sent, msat;
537 struct node_id destination;
538 u32 created_at;
539
540 err = json_get_member(buf, result, "error");
541 if (err)
542 return command_fail(
543 cmd, LIGHTNINGD,
544 "Error retrieving previous pay attempts: %s",
545 json_strdup(tmpctx, buf, err));
546
547 arr = json_get_member(buf, result, "payments");
548 if (!arr || arr->type != JSMN_ARRAY)
549 return command_fail(
550 cmd, LIGHTNINGD,
551 "Unexpected non-array result from listsendpays");
552
553 /* We iterate through all prior sendpays, looking for the
554 * latest group and remembering what its state is. */
555 json_for_each_arr(i, t, arr)
556 {
557 u64 groupid;
558 const jsmntok_t *status, *grouptok;
559 struct amount_msat diff_sent, diff_msat;
560 grouptok = json_get_member(buf, t, "groupid");
561 json_to_u64(buf, grouptok, &groupid);
562
563 /* New group, reset what we collected. */
564 if (last_group != groupid) {
565 completed = false;
566 pending = false;
567 last_group = groupid;
568
569 parts = 1;

Callers

nothing calls this directly

Calls 15

json_get_memberFunction · 0.85
amount_msat_accumulateFunction · 0.85
json_tok_streqFunction · 0.85
json_add_preimageFunction · 0.85
json_add_amount_msatFunction · 0.85
json_add_node_idFunction · 0.85
json_add_sha256Function · 0.85
json_add_u32Function · 0.85
json_add_numFunction · 0.85
node_id_eqFunction · 0.85
command_failFunction · 0.70
plugin_errFunction · 0.70

Tested by

no test coverage detected