Skip to content

Commit

Permalink
renepay: add json helper for route hops
Browse files Browse the repository at this point in the history
Signed-off-by: Lagrang3 <[email protected]>
  • Loading branch information
Lagrang3 committed Sep 19, 2024
1 parent 42d5600 commit ef0aa60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
35 changes: 19 additions & 16 deletions plugins/renepay/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,24 @@ void json_add_payment(struct json_stream *s, const struct payment *payment)
// - number of parts?
}

void json_add_route_hops(struct json_stream *js, const char *fieldname,
const struct route_hop *hops)
{
const size_t pathlen = tal_count(hops);
json_array_start(js, fieldname);
for (size_t j = 0; j < pathlen; j++) {
const struct route_hop *h = &hops[j];
json_object_start(js, NULL);
json_add_node_id(js, "id", &h->node_id);
json_add_short_channel_id(js, "channel", h->scid);
json_add_amount_msat(js, "amount_msat", h->amount);
json_add_num(js, "direction", h->direction);
json_add_u32(js, "delay", h->delay);
json_object_end(js);
}
json_array_end(js);
}

void json_add_route(struct json_stream *js, const struct route *route,
const struct payment *payment)
{
Expand All @@ -273,22 +291,7 @@ void json_add_route(struct json_stream *js, const struct route *route,

assert(route->hops);
const size_t pathlen = tal_count(route->hops);

json_array_start(js, "route");
/* An empty route means a payment to oneself, pathlen=0 */
for (size_t j = 0; j < pathlen; j++) {
const struct route_hop *hop = &route->hops[j];

json_object_start(js, NULL);
json_add_node_id(js, "id", &hop->node_id);
json_add_short_channel_id(js, "channel", hop->scid);
json_add_amount_msat(js, "amount_msat", hop->amount);
json_add_num(js, "direction", hop->direction);
json_add_u32(js, "delay", hop->delay);
json_add_string(js, "style", "tlv");
json_object_end(js);
}
json_array_end(js);
json_add_route_hops(js, "route", route->hops);
json_add_sha256(js, "payment_hash", &pinfo->payment_hash);

if (pinfo->payment_secret)
Expand Down
3 changes: 3 additions & 0 deletions plugins/renepay/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ struct payment_result *tal_sendpay_result_from_json(const tal_t *ctx,

void json_add_payment(struct json_stream *s, const struct payment *payment);

void json_add_route_hops(struct json_stream *js, const char *fieldname,
const struct route_hop *hops);

void json_add_route(struct json_stream *s, const struct route *route,
const struct payment *payment);

Expand Down

0 comments on commit ef0aa60

Please sign in to comment.