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

Function json_add_payment_success

plugins/libplugin-pay.c:2139–2187  ·  view source on GitHub ↗

Code shared by selfpay fast-path: populate JSON output for successful * payment, and send pay_success notification. */

Source from the content-addressed store, hash-verified

2137/* Code shared by selfpay fast-path: populate JSON output for successful
2138 * payment, and send pay_success notification. */
2139void json_add_payment_success(struct json_stream *js,
2140 struct payment *p,
2141 const struct preimage *preimage,
2142 const struct payment_tree_result *result)
2143{
2144 struct json_stream *n;
2145 struct payment *root = payment_root(p);
2146
2147 json_add_node_id(js, "destination", p->pay_destination);
2148 json_add_sha256(js, "payment_hash", p->payment_hash);
2149 json_add_timeabs(js, "created_at", p->start_time);
2150 if (result)
2151 json_add_num(js, "parts", result->attempts);
2152 else
2153 json_add_num(js, "parts", 1);
2154
2155 json_add_amount_msat(js, "amount_msat", p->our_amount);
2156 if (result)
2157 json_add_amount_msat(js, "amount_sent_msat", result->sent);
2158 else
2159 json_add_amount_msat(js, "amount_sent_msat", p->our_amount);
2160
2161 if (result && result->leafstates != PAYMENT_STEP_SUCCESS)
2162 json_add_string(js, "warning_partial_completion",
2163 "Some parts of the payment are not yet "
2164 "completed, but we have the confirmation "
2165 "from the recipient.");
2166 json_add_preimage(js, "payment_preimage", preimage);
2167 json_add_string(js, "status", "complete");
2168
2169 n = plugin_notification_start_obs(p->plugin, "pay_success");
2170 /* Fake up the old "payload" style, *and* the old unwrapped style */
2171 if (notification_deprecated_out_ok(p->plugin, "notification", "payload",
2172 "v25.09", "v26.09")) {
2173 json_add_string(n, "origin", "pay");
2174 json_object_start(n, "payload");
2175 json_add_sha256(n, "payment_hash", p->payment_hash);
2176 if (root->invstring != NULL)
2177 json_add_string(n, "bolt11", root->invstring);
2178 json_object_end(n);
2179 }
2180
2181 json_object_start(n, "pay_success");
2182 json_add_sha256(n, "payment_hash", p->payment_hash);
2183 if (root->invstring != NULL)
2184 json_add_string(n, "bolt11", root->invstring);
2185 json_object_end(n);
2186 plugin_notification_end_obs(p->plugin, n);
2187}
2188
2189/* This function is called whenever a payment ends up in a final state, or all
2190 * leafs in the subtree rooted in the payment are all in a final state. It is

Callers 2

selfpay_successFunction · 0.85
payment_finishedFunction · 0.85

Calls 13

payment_rootFunction · 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
json_object_startFunction · 0.85
json_object_endFunction · 0.85

Tested by

no test coverage detected