lightningd: add listpeerchannels command

Changelog-Added: JSON-RPC: new command `listpeerchannels` now contains information on direct channels with our peers.

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
Vincenzo Palazzo
2023-01-12 11:46:10 +10:30
committed by Rusty Russell
parent 1d8b899551
commit 6fa904b4fb
7 changed files with 1403 additions and 0 deletions

View File

@@ -2047,6 +2047,60 @@ static const struct json_command staticbackup_command = {
/* Comment added to satisfice AUTODATA */
AUTODATA(json_command, &staticbackup_command);
static void json_add_peerchannels(struct lightningd *ld,
struct json_stream *response,
const struct peer *peer)
{
struct channel *channel;
json_add_uncommitted_channel(response, peer->uncommitted_channel, peer);
list_for_each(&peer->channels, channel, list) {
if (channel_unsaved(channel))
json_add_unsaved_channel(response, channel, peer);
else
json_add_channel(ld, response, NULL, channel, peer);
}
}
static struct command_result *json_listpeerchannels(struct command *cmd,
const char *buffer,
const jsmntok_t *obj UNNEEDED,
const jsmntok_t *params)
{
struct node_id *peer_id;
struct peer *peer;
struct json_stream *response;
/* FIME: filter by status */
if (!param(cmd, buffer, params,
p_opt("id", param_node_id, &peer_id),
NULL))
return command_param_failed();
response = json_stream_success(cmd);
json_array_start(response, "channels");
if (peer_id) {
peer = peer_by_id(cmd->ld, peer_id);
if (peer)
json_add_peerchannels(cmd->ld, response, peer);
} else {
list_for_each(&cmd->ld->peers, peer, list)
json_add_peerchannels(cmd->ld, response, peer);
}
json_array_end(response);
return command_success(cmd, response);
}
static const struct json_command listpeerchannels_command = {
"listpeerchannels",
"network",
json_listpeerchannels,
"Show channels with direct peers."
};
AUTODATA(json_command, &listpeerchannels_command);
struct command_result *
command_find_channel(struct command *cmd,