| 3026 | } |
| 3027 | |
| 3028 | static struct command_result *json_listpeerchannels(struct command *cmd, |
| 3029 | const char *buffer, |
| 3030 | const jsmntok_t *obj UNNEEDED, |
| 3031 | const jsmntok_t *params) |
| 3032 | { |
| 3033 | struct node_id *peer_id; |
| 3034 | struct peer *peer; |
| 3035 | struct json_stream *response; |
| 3036 | struct short_channel_id *scid; |
| 3037 | struct channel_id *cid; |
| 3038 | |
| 3039 | if (!param_check(cmd, buffer, params, |
| 3040 | p_opt("id", param_node_id, &peer_id), |
| 3041 | p_opt("short_channel_id", param_short_channel_id, &scid), |
| 3042 | p_opt("channel_id", param_channel_id, &cid), |
| 3043 | NULL)) |
| 3044 | return command_param_failed(); |
| 3045 | |
| 3046 | int count = (peer_id != NULL) + (scid != NULL) + (cid != NULL); |
| 3047 | if (count > 1) { |
| 3048 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 3049 | "Must not specify more than one of " |
| 3050 | "short_channel_id, channel_id or id" |
| 3051 | ); |
| 3052 | } |
| 3053 | |
| 3054 | response = json_stream_success(cmd); |
| 3055 | json_array_start(response, "channels"); |
| 3056 | |
| 3057 | if (peer_id) { |
| 3058 | peer = peer_by_id(cmd->ld, peer_id); |
| 3059 | if (peer) |
| 3060 | json_add_peerchannels(cmd, response, peer); |
| 3061 | } else if (scid) { |
| 3062 | const struct channel *c = any_channel_by_scid(cmd->ld, *scid, true); |
| 3063 | if (c) |
| 3064 | json_add_channel(cmd, response, NULL, c, c->peer); |
| 3065 | } else if (cid) { |
| 3066 | const struct channel *c = channel_by_cid(cmd->ld, cid); |
| 3067 | if (c) |
| 3068 | json_add_channel(cmd, response, NULL, c, c->peer); |
| 3069 | } else { |
| 3070 | struct peer_node_id_map_iter it; |
| 3071 | |
| 3072 | for (peer = peer_node_id_map_first(cmd->ld->peers, &it); |
| 3073 | peer; |
| 3074 | peer = peer_node_id_map_next(cmd->ld->peers, &it)) { |
| 3075 | json_add_peerchannels(cmd, response, peer); |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | json_array_end(response); |
| 3080 | |
| 3081 | return command_success(cmd, response); |
| 3082 | } |
| 3083 | |
| 3084 | static const struct json_command listpeerchannels_command = { |
| 3085 | "listpeerchannels", |
nothing calls this directly
no test coverage detected