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

Function success_data_from_listsendpays

plugins/renepay/mods.c:116–189  ·  view source on GitHub ↗

Extracts success data from listsendpays. */

Source from the content-addressed store, hash-verified

114
115/* Extracts success data from listsendpays. */
116static bool success_data_from_listsendpays(const char *buf,
117 const jsmntok_t *arr,
118 struct success_data *success)
119{
120 assert(success);
121
122 size_t i;
123 const char *err;
124 const jsmntok_t *t;
125 assert(arr && arr->type == JSMN_ARRAY);
126
127 success->parts = 0;
128 success->deliver_msat = AMOUNT_MSAT(0);
129 success->sent_msat = AMOUNT_MSAT(0);
130
131 json_for_each_arr(i, t, arr)
132 {
133 u64 groupid;
134 struct amount_msat this_msat, this_sent;
135
136 const jsmntok_t *status_tok = json_get_member(buf, t, "status");
137 if (!status_tok)
138 plugin_err(
139 pay_plugin->plugin,
140 "%s (line %d) missing status token from json.",
141 __func__, __LINE__);
142 const char *status = json_strdup(tmpctx, buf, status_tok);
143 if (!status)
144 plugin_err(
145 pay_plugin->plugin,
146 "%s (line %d) failed to allocate status string.",
147 __func__, __LINE__);
148
149 if (streq(status, "complete")) {
150 /* FIXME we assume amount_msat is always present, but
151 * according to the documentation this field is
152 * optional. How do I interpret if amount_msat is
153 * missing? */
154 err = json_scan(
155 tmpctx, buf, t,
156 "{groupid:%"
157 ",amount_msat:%"
158 ",amount_sent_msat:%"
159 ",created_at:%"
160 ",payment_preimage:%}",
161 JSON_SCAN(json_to_u64, &groupid),
162 JSON_SCAN(json_to_msat, &this_msat),
163 JSON_SCAN(json_to_msat, &this_sent),
164 JSON_SCAN(json_to_u64, &success->created_at),
165 JSON_SCAN(json_to_preimage, &success->preimage));
166
167 if (err)
168 plugin_err(pay_plugin->plugin,
169 "%s (line %d) json_scan of "
170 "listsendpay returns the "
171 "following error: %s",
172 __func__, __LINE__, err);
173 success->groupid = groupid;

Callers 2

previoussuccess_doneFunction · 0.85
pendingsendpays_doneFunction · 0.85

Calls 5

json_get_memberFunction · 0.85
amount_msat_addFunction · 0.85
plugin_errFunction · 0.50
json_strdupFunction · 0.50
json_scanFunction · 0.50

Tested by

no test coverage detected