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

Function json_add_payment

plugins/renepay/json.c:256–308  ·  view source on GitHub ↗

TODO add verbose option to include more or less details or change the schema, checkout docs/schema/renepay.schema.json and docs/schema/renepaystatus.schema.json

Source from the content-addressed store, hash-verified

254// checkout docs/schema/renepay.schema.json and
255// docs/schema/renepaystatus.schema.json
256void json_add_payment(struct json_stream *s, const struct payment *payment)
257{
258 assert(s);
259 assert(payment);
260 const struct payment_info *pinfo = &payment->payment_info;
261
262 if (pinfo->label != NULL)
263 json_add_string(s, "label", pinfo->label);
264 if (pinfo->invstr != NULL)
265 json_add_invstring(s, pinfo->invstr);
266
267 json_add_amount_msat(s, "amount_msat", pinfo->amount);
268 json_add_sha256(s, "payment_hash", &pinfo->payment_hash);
269 json_add_node_id(s, "destination", &pinfo->destination);
270
271 /* FIXME: we have not declared "description" in renepay's response
272 * schema
273 if (pinfo->description)
274 json_add_string(s, "description", pinfo->description);
275 */
276
277 json_add_timeabs(s, "created_at", pinfo->start_time);
278 json_add_u64(s, "groupid", payment->groupid);
279 json_add_u64(s, "parts", payment->next_partid);
280
281 switch (payment->status) {
282 case PAYMENT_SUCCESS:
283 assert(payment->preimage);
284
285 json_add_string(s, "status", "complete");
286 json_add_preimage(s, "payment_preimage", payment->preimage);
287 json_add_amount_msat(s, "amount_sent_msat",
288 payment->total_sent);
289 break;
290 case PAYMENT_FAIL:
291 json_add_string(s, "status", "failed");
292 break;
293 case PAYMENT_PENDING:
294 json_add_string(s, "status", "pending");
295 break;
296 }
297
298 // FIXME: add more verbose outputs?
299 // json_array_start(s, "notes");
300 // for (size_t i = 0; i < tal_count(payment->paynotes); i++)
301 // json_add_string(s, NULL, payment->paynotes[i]);
302 // json_array_end(s);
303
304 // TODO(eduardo): maybe we should add also:
305 // - payment_secret?
306 // - payment_metadata?
307 // - number of parts?
308}
309
310void json_add_route(struct json_stream *js, const struct route *route,
311 const struct payment *payment)

Callers 3

my_command_finishFunction · 0.70
json_renepaystatusFunction · 0.70
json_renepayFunction · 0.70

Calls 8

json_add_invstringFunction · 0.85
json_add_amount_msatFunction · 0.85
json_add_sha256Function · 0.85
json_add_node_idFunction · 0.85
json_add_timeabsFunction · 0.85
json_add_u64Function · 0.85
json_add_preimageFunction · 0.85
json_add_stringFunction · 0.50

Tested by

no test coverage detected