Skip to content

Commit

Permalink
Add json API for struct route_exclusion
Browse files Browse the repository at this point in the history
To be able to write a route_exclusion to a json stream.

Changelog-None.

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
  • Loading branch information
Lagrang3 committed Sep 23, 2024
1 parent 0a6870f commit e78c102
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions common/json_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <common/json_parse.h>
#include <common/json_stream.h>
#include <common/node_id.h>
#include <common/route.h>
#include <common/wireaddr.h>
#include <inttypes.h>
#include <stdio.h>
Expand Down Expand Up @@ -494,6 +495,17 @@ void json_add_short_channel_id_dir(struct json_stream *response,
short_channel_id_outnum(scidd.scid), scidd.dir);
}

void json_add_route_exclusion(struct json_stream *response,
const char *fieldname,
const struct route_exclusion *ex)
{
if (ex->type == EXCLUDE_NODE)
json_add_node_id(response, fieldname, &ex->u.node_id);
else
json_add_short_channel_id_dir(response, fieldname,
ex->u.chan_id);
}

static void json_add_address_fields(struct json_stream *response,
const struct wireaddr *addr,
const char *typefield)
Expand Down
7 changes: 7 additions & 0 deletions common/json_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct wally_psbt;
struct lease_rates;
struct wireaddr;
struct wireaddr_internal;
struct route_exclusion;

struct json_stream {
struct json_out *jout;
Expand Down Expand Up @@ -301,6 +302,12 @@ void json_add_channel_id(struct json_stream *response,
const char *fieldname,
const struct channel_id *cid);

/* '"fieldname" : <value>' or "<value>" if fieldname is NULL, where <value> is
* either a node_id or a short_channel_id_dir. */
void json_add_route_exclusion(struct json_stream *response,
const char *fieldname,
const struct route_exclusion *ex);

/* '"fieldname" : <hexrev>' or "<hexrev>" if fieldname is NULL */
void json_add_txid(struct json_stream *result, const char *fieldname,
const struct bitcoin_txid *txid);
Expand Down

0 comments on commit e78c102

Please sign in to comment.