lightningd: move json_add_route into gossip_control.c and make static.

There's only one caller.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-11-14 10:47:53 +10:30 committed by Christian Decker
parent 3a25e9b8d6
commit 997e3f7fe6
3 changed files with 27 additions and 34 deletions

View File

@ -303,6 +303,33 @@ static const struct json_command listnodes_command = {
};
AUTODATA(json_command, &listnodes_command);
/* Output a route hop */
static void json_add_route_hop(struct json_stream *r, char const *n,
const struct route_hop *h)
{
/* Imitate what getroute/sendpay use */
json_object_start(r, n);
json_add_node_id(r, "id", &h->nodeid);
json_add_short_channel_id(r, "channel",
&h->channel_id);
json_add_num(r, "direction", h->direction);
json_add_amount_msat_compat(r, h->amount, "msatoshi", "amount_msat");
json_add_num(r, "delay", h->delay);
json_object_end(r);
}
/* Output a route */
static void json_add_route(struct json_stream *r, char const *n,
const struct route_hop *hops, size_t hops_len)
{
size_t i;
json_array_start(r, n);
for (i = 0; i < hops_len; ++i) {
json_add_route_hop(r, NULL, &hops[i]);
}
json_array_end(r);
}
static void json_getroute_reply(struct subd *gossip UNUSED, const u8 *reply, const int *fds UNUSED,
struct command *cmd)
{

View File

@ -27,35 +27,6 @@
#include <wallet/wallet.h>
#include <wire/wire.h>
/* Output a route hop */
static void
json_add_route_hop(struct json_stream *r, char const *n,
const struct route_hop *h)
{
/* Imitate what getroute/sendpay use */
json_object_start(r, n);
json_add_node_id(r, "id", &h->nodeid);
json_add_short_channel_id(r, "channel",
&h->channel_id);
json_add_num(r, "direction", h->direction);
json_add_amount_msat_compat(r, h->amount, "msatoshi", "amount_msat");
json_add_num(r, "delay", h->delay);
json_object_end(r);
}
/* Output a route */
void
json_add_route(struct json_stream *r, char const *n,
const struct route_hop *hops, size_t hops_len)
{
size_t i;
json_array_start(r, n);
for (i = 0; i < hops_len; ++i) {
json_add_route_hop(r, NULL, &hops[i]);
}
json_array_end(r);
}
void json_add_node_id(struct json_stream *response,
const char *fieldname,
const struct node_id *id)

View File

@ -26,7 +26,6 @@ struct json_escape;
struct json_stream;
struct pubkey;
struct node_id;
struct route_hop;
struct sha256;
struct short_channel_id;
struct wallet_payment;
@ -34,10 +33,6 @@ struct wallet_tx;
struct wireaddr;
struct wireaddr_internal;
/* Output a route array. */
void json_add_route(struct json_stream *r, char const *n,
const struct route_hop *hops, size_t hops_len);
/* '"fieldname" : "0289abcdef..."' or "0289abcdef..." if fieldname is NULL */
void json_add_pubkey(struct json_stream *response,
const char *fieldname,