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

Function json_add_route

plugins/renepay/json.c:310–371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

308}
309
310void json_add_route(struct json_stream *js, const struct route *route,
311 const struct payment *payment)
312{
313 assert(js);
314 assert(route);
315 assert(payment);
316
317 const struct payment_info *pinfo = &payment->payment_info;
318
319 assert(route->hops);
320 const size_t pathlen = tal_count(route->hops);
321
322 json_array_start(js, "route");
323 /* An empty route means a payment to oneself, pathlen=0 */
324 for (size_t j = 0; j < pathlen; j++) {
325 const struct route_hop *hop = &route->hops[j];
326
327 json_object_start(js, NULL);
328 json_add_node_id(js, "id", &hop->node_id);
329 json_add_short_channel_id(js, "channel", hop->scid);
330 json_add_amount_msat(js, "amount_msat", hop->amount);
331 json_add_num(js, "direction", hop->direction);
332 json_add_u32(js, "delay", hop->delay);
333 json_add_string(js, "style", "tlv");
334 json_object_end(js);
335 }
336 json_array_end(js);
337 json_add_sha256(js, "payment_hash", &pinfo->payment_hash);
338
339 if (pinfo->payment_secret)
340 json_add_secret(js, "payment_secret", pinfo->payment_secret);
341
342 /* FIXME: sendpay has a check that we don't total more than
343 * the exact amount, if we're setting partid (i.e. MPP).
344 * However, we always set partid, and we add a shadow amount if
345 * we've only have one part, so we have to use that amount
346 * here.
347 *
348 * The spec was loosened so you are actually allowed
349 * to overpay, so this check is now overzealous. */
350 if (pathlen > 0 &&
351 amount_msat_greater(route_delivers(route), pinfo->amount)) {
352 json_add_amount_msat(js, "amount_msat", route_delivers(route));
353 } else {
354 json_add_amount_msat(js, "amount_msat", pinfo->amount);
355 }
356 json_add_u64(js, "partid", route->key.partid);
357 json_add_u64(js, "groupid", route->key.groupid);
358
359 /* FIXME: some of these fields might not be required for all
360 * payment parts. */
361 json_add_string(js, "bolt11", pinfo->invstr);
362
363 if (pinfo->payment_metadata)
364 json_add_hex_talarr(js, "payment_metadata",
365 pinfo->payment_metadata);
366 if (pinfo->label)
367 json_add_string(js, "label", pinfo->label);

Callers

nothing calls this directly

Calls 15

json_array_startFunction · 0.85
json_object_startFunction · 0.85
json_add_node_idFunction · 0.85
json_add_amount_msatFunction · 0.85
json_add_numFunction · 0.85
json_add_u32Function · 0.85
json_object_endFunction · 0.85
json_array_endFunction · 0.85
json_add_sha256Function · 0.85
json_add_secretFunction · 0.85
amount_msat_greaterFunction · 0.85

Tested by

no test coverage detected