diff --git a/daemon/jsonrpc.c b/daemon/jsonrpc.c index f44958592..1330c2519 100644 --- a/daemon/jsonrpc.c +++ b/daemon/jsonrpc.c @@ -294,6 +294,7 @@ static const struct json_command *cmdlist[] = { &listinvoice_command, &delinvoice_command, &waitinvoice_command, + &getchannels_command, &getroute_command, &sendpay_command, &getinfo_command, diff --git a/daemon/jsonrpc.h b/daemon/jsonrpc.h index 4c5ad6159..20d9cef6e 100644 --- a/daemon/jsonrpc.h +++ b/daemon/jsonrpc.h @@ -60,6 +60,7 @@ void setup_jsonrpc(struct lightningd_state *dstate, const char *rpc_filename); extern const struct json_command newaddr_command; extern const struct json_command connect_command; extern const struct json_command close_command; +extern const struct json_command getchannels_command; extern const struct json_command getpeers_command; /* Invoice management. */ diff --git a/daemon/routing.c b/daemon/routing.c index 1b63a5669..e2fddf5b0 100644 --- a/daemon/routing.c +++ b/daemon/routing.c @@ -451,7 +451,7 @@ static void json_add_route(struct command *cmd, add_connection(cmd->dstate, &src, &dst, base, var, delay, minblocks); command_success(cmd, null_response(cmd)); } - + const struct json_command dev_add_route_command = { "dev-add-route", json_add_route, @@ -459,6 +459,42 @@ const struct json_command dev_add_route_command = { "Returns an empty result on success" }; +static void json_getchannels(struct command *cmd, + const char *buffer, const jsmntok_t *params) +{ + struct json_result *response = new_json_result(cmd); + struct node_map_iter it; + struct node *n; + struct node_map *nodes = cmd->dstate->nodes; + struct node_connection *c; + int num_conn, i; + + json_object_start(response, NULL); + json_array_start(response, "channels"); + for (n = node_map_first(nodes, &it); n; n = node_map_next(nodes, &it)) { + num_conn = tal_count(n->out); + for (i = 0; i < num_conn; i++){ + c = n->out[i]; + json_object_start(response, NULL); + json_add_pubkey(response, cmd->dstate->secpctx, "from", &n->id); + json_add_pubkey(response, cmd->dstate->secpctx, "to", &c->dst->id); + json_add_num(response, "base_fee", c->base_fee); + json_add_num(response, "proportional_fee", c->proportional_fee); + json_object_end(response); + } + } + json_array_end(response); + json_object_end(response); + command_success(cmd, response); +} + +const struct json_command getchannels_command = { + "getchannels", + json_getchannels, + "List all known channels.", + "Returns a 'channels' array with all known channels including their fees." +}; + static void json_routefail(struct command *cmd, const char *buffer, const jsmntok_t *params) {