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

Function on_payment_success

plugins/pay.c:596–649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

594}
595
596static void on_payment_success(struct payment *payment)
597{
598 struct payment *p, *nxt;
599 struct payment_tree_result result = payment_collect_result(payment);
600 struct json_stream *ret;
601 struct command *cmd;
602 assert(result.treestates & PAYMENT_STEP_SUCCESS);
603 assert(result.leafstates & PAYMENT_STEP_SUCCESS);
604 assert(result.preimage != NULL);
605
606 /* Iterate through any pending payments we suspended and
607 * terminate them. */
608
609 list_for_each_safe(&payments, p, nxt, list) {
610 /* The result for the active payment is returned in
611 * `payment_finished`. */
612 if (payment == p)
613 continue;
614
615 /* Both groupid and payment_hash must match. This is
616 * because when we suspended the payment itself, we
617 * set the groupid to match. */
618 if (!sha256_eq(payment->payment_hash, p->payment_hash) ||
619 payment->groupid != p->groupid)
620 continue;
621 if (p->cmd == NULL)
622 continue;
623
624 cmd = p->cmd;
625 p->cmd = NULL;
626
627 ret = jsonrpc_stream_success(cmd);
628 json_add_node_id(ret, "destination", p->destination);
629 json_add_sha256(ret, "payment_hash", p->payment_hash);
630 json_add_timeabs(ret, "created_at", p->start_time);
631 json_add_num(ret, "parts", result.attempts);
632
633 json_add_amount_msat_compat(ret, p->amount, "msatoshi",
634 "amount_msat");
635 json_add_amount_msat_compat(ret, result.sent, "msatoshi_sent",
636 "amount_sent_msat");
637
638 if (result.leafstates != PAYMENT_STEP_SUCCESS)
639 json_add_string(
640 ret, "warning_partial_completion",
641 "Some parts of the payment are not yet "
642 "completed, but we have the confirmation "
643 "from the recipient.");
644 json_add_preimage(ret, "payment_preimage", result.preimage);
645
646 json_add_string(ret, "status", "complete");
647 if (command_finished(cmd, ret)) {/* Ignore result. */}
648 }
649}
650
651static void payment_add_attempt(struct json_stream *s, const char *fieldname, struct payment *p, bool recurse)
652{

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected