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