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. */
| 510 | * about an eventual previous complete payment so we can return that |
| 511 | * as a no-op. */ |
| 512 | static struct command_result * |
| 513 | payment_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; |
nothing calls this directly
no test coverage detected