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

Function payment_listsendpays_previous

plugins/pay.c:812–928  ·  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

810 * about an eventual previous complete payment so we can return that
811 * as a no-op. */
812static struct command_result *
813payment_listsendpays_previous(struct command *cmd, const char *buf,
814 const jsmntok_t *result, struct payment *p)
815{
816 size_t i;
817 const jsmntok_t *t, *arr, *err;
818 /* What was the groupid of an eventual previous attempt? */
819 u64 last_group = 0;
820 /* Do we have pending sendpays for the previous attempt? */
821 bool pending = false;
822
823 /* Group ID of the first pending payment, this will be the one
824 * who's result gets replayed if we end up suspending. */
825 u64 pending_group_id = 0;
826 /* Did a prior attempt succeed? */
827 bool completed = false;
828
829 /* Metadata for a complete payment, if one exists. */
830 struct json_stream *ret;
831 u32 parts = 0;
832 struct preimage preimage;
833 struct amount_msat sent, msat;
834 struct node_id destination;
835 u32 created_at;
836
837 err = json_get_member(buf, result, "error");
838 if (err)
839 return command_fail(
840 cmd, LIGHTNINGD,
841 "Error retrieving previous pay attempts: %s",
842 json_strdup(tmpctx, buf, err));
843
844 arr = json_get_member(buf, result, "payments");
845 if (!arr || arr->type != JSMN_ARRAY)
846 return command_fail(
847 cmd, LIGHTNINGD,
848 "Unexpected non-array result from listsendpays");
849
850 /* We iterate through all prior sendpays, looking for the
851 * latest group and remembering what its state is. */
852 json_for_each_arr(i, t, arr)
853 {
854 u64 groupid;
855 const jsmntok_t *status, *grouptok;
856 struct amount_msat diff_sent, diff_msat;
857 grouptok = json_get_member(buf, t, "groupid");
858 json_to_u64(buf, grouptok, &groupid);
859
860 /* New group, reset what we collected. */
861 if (last_group != groupid) {
862 completed = false;
863 pending = false;
864 last_group = groupid;
865
866 parts = 1;
867 json_scan(tmpctx, buf, t,
868 "{destination:%"
869 ",created_at:%"

Callers

nothing calls this directly

Calls 15

amount_msat_addFunction · 0.85
payment_startFunction · 0.85
command_failFunction · 0.70
plugin_errFunction · 0.70
jsonrpc_stream_successFunction · 0.70
command_finishedFunction · 0.70
command_still_pendingFunction · 0.70
json_get_memberFunction · 0.50
json_strdupFunction · 0.50
json_to_u64Function · 0.50
json_scanFunction · 0.50
json_tok_streqFunction · 0.50

Tested by

no test coverage detected