mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +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:
parent
356bb73fe9
commit
8e2abfcc70
@ -292,6 +292,7 @@ static const struct json_command *cmdlist[] = {
|
|||||||
&listinvoice_command,
|
&listinvoice_command,
|
||||||
&delinvoice_command,
|
&delinvoice_command,
|
||||||
&waitinvoice_command,
|
&waitinvoice_command,
|
||||||
|
&getchannels_command,
|
||||||
&getroute_command,
|
&getroute_command,
|
||||||
&sendpay_command,
|
&sendpay_command,
|
||||||
&getinfo_command,
|
&getinfo_command,
|
||||||
|
@ -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 newaddr_command;
|
||||||
extern const struct json_command connect_command;
|
extern const struct json_command connect_command;
|
||||||
extern const struct json_command close_command;
|
extern const struct json_command close_command;
|
||||||
|
extern const struct json_command getchannels_command;
|
||||||
extern const struct json_command getpeers_command;
|
extern const struct json_command getpeers_command;
|
||||||
|
|
||||||
/* Invoice management. */
|
/* Invoice management. */
|
||||||
|
@ -451,7 +451,7 @@ static void json_add_route(struct command *cmd,
|
|||||||
add_connection(cmd->dstate, &src, &dst, base, var, delay, minblocks);
|
add_connection(cmd->dstate, &src, &dst, base, var, delay, minblocks);
|
||||||
command_success(cmd, null_response(cmd));
|
command_success(cmd, null_response(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct json_command dev_add_route_command = {
|
const struct json_command dev_add_route_command = {
|
||||||
"dev-add-route",
|
"dev-add-route",
|
||||||
json_add_route,
|
json_add_route,
|
||||||
@ -459,6 +459,42 @@ const struct json_command dev_add_route_command = {
|
|||||||
"Returns an empty result on success"
|
"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,
|
static void json_routefail(struct command *cmd,
|
||||||
const char *buffer, const jsmntok_t *params)
|
const char *buffer, const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user