mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-23 00:54:20 +01:00
jsonrpc: Added 'getchannels' RPC method.
'getchannels' returns a 'channels' array containing an object for each known channel. Each channel object represents one direction of a bidirectional channel, with a from and a to node ID along with the fees for that direction. This matched the internal storage of channels and allows unbalanced fees for each direction.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user