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

Function on_payment_success

plugins/pay.c:248–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246}
247
248static void on_payment_success(struct payment *payment)
249{
250 struct payment *p, *nxt;
251 struct payment_tree_result result = payment_collect_result(payment);
252 struct json_stream *ret;
253 struct command *cmd;
254 assert(result.treestates & PAYMENT_STEP_SUCCESS);
255 assert(result.leafstates & PAYMENT_STEP_SUCCESS);
256 assert(result.preimage != NULL);
257
258 /* Iterate through any pending payments we suspended and
259 * terminate them. */
260
261 list_for_each_safe(&payments, p, nxt, list) {
262 /* The result for the active payment is returned in
263 * `payment_finished`. */
264 if (payment == p)
265 continue;
266
267 /* Both groupid and payment_hash must match. This is
268 * because when we suspended the payment itself, we
269 * set the groupid to match. */
270 if (!sha256_eq(payment->payment_hash, p->payment_hash) ||
271 payment->groupid != p->groupid)
272 continue;
273 if (p->finished)
274 continue;
275
276 cmd = p->cmd;
277 p->cmd = aux_command(cmd);
278 p->finished = true;
279
280 ret = jsonrpc_stream_success(cmd);
281 json_add_node_id(ret, "destination", p->pay_destination);
282 json_add_sha256(ret, "payment_hash", p->payment_hash);
283 json_add_timeabs(ret, "created_at", p->start_time);
284 json_add_num(ret, "parts", result.attempts);
285
286 json_add_amount_msat(ret, "amount_msat", p->our_amount);
287 json_add_amount_msat(ret, "amount_sent_msat", result.sent);
288
289 if (result.leafstates != PAYMENT_STEP_SUCCESS)
290 json_add_string(
291 ret, "warning_partial_completion",
292 "Some parts of the payment are not yet "
293 "completed, but we have the confirmation "
294 "from the recipient.");
295 json_add_preimage(ret, "payment_preimage", result.preimage);
296
297 json_add_string(ret, "status", "complete");
298 if (command_finished(cmd, ret)) {/* Ignore result. */}
299 }
300}
301
302static void payment_add_attempt(struct json_stream *s, const char *fieldname, struct payment *p, bool recurse)
303{

Callers

nothing calls this directly

Calls 11

payment_collect_resultFunction · 0.85
json_add_node_idFunction · 0.85
json_add_sha256Function · 0.85
json_add_timeabsFunction · 0.85
json_add_numFunction · 0.85
json_add_amount_msatFunction · 0.85
json_add_preimageFunction · 0.85
aux_commandFunction · 0.70
jsonrpc_stream_successFunction · 0.70
command_finishedFunction · 0.70
json_add_stringFunction · 0.50

Tested by

no test coverage detected