| 268 | } |
| 269 | |
| 270 | static struct command_result *json_listchannels(struct command *cmd, |
| 271 | const char *buffer, |
| 272 | const jsmntok_t *params) |
| 273 | { |
| 274 | struct node_id *source; |
| 275 | struct node_id *destination; |
| 276 | struct short_channel_id *scid; |
| 277 | struct gossmap_chan *c; |
| 278 | struct json_stream *js; |
| 279 | struct gossmap *gossmap; |
| 280 | |
| 281 | if (!param(cmd, buffer, params, |
| 282 | p_opt("short_channel_id", param_short_channel_id, |
| 283 | &scid), |
| 284 | p_opt("source", param_node_id, &source), |
| 285 | p_opt("destination", param_node_id, &destination), |
| 286 | NULL)) |
| 287 | return command_param_failed(); |
| 288 | |
| 289 | if (!!scid + !!source + !!destination > 1) |
| 290 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 291 | "Can only specify one of " |
| 292 | "`short_channel_id`, " |
| 293 | "`source` or `destination`"); |
| 294 | |
| 295 | gossmap = get_gossmap(); |
| 296 | js = jsonrpc_stream_success(cmd); |
| 297 | json_array_start(js, "channels"); |
| 298 | if (scid) { |
| 299 | c = gossmap_find_chan(gossmap, scid); |
| 300 | if (c) |
| 301 | json_add_halfchan(js, gossmap, c, 3); |
| 302 | } else if (source) { |
| 303 | struct gossmap_node *src; |
| 304 | |
| 305 | src = gossmap_find_node(gossmap, source); |
| 306 | if (src) { |
| 307 | for (size_t i = 0; i < src->num_chans; i++) { |
| 308 | int dir; |
| 309 | c = gossmap_nth_chan(gossmap, src, i, &dir); |
| 310 | json_add_halfchan(js, gossmap, |
| 311 | c, 1 << dir); |
| 312 | } |
| 313 | } |
| 314 | } else if (destination) { |
| 315 | struct gossmap_node *dst; |
| 316 | |
| 317 | dst = gossmap_find_node(gossmap, destination); |
| 318 | if (dst) { |
| 319 | for (size_t i = 0; i < dst->num_chans; i++) { |
| 320 | int dir; |
| 321 | c = gossmap_nth_chan(gossmap, dst, i, &dir); |
| 322 | json_add_halfchan(js, gossmap, |
| 323 | c, 1 << !dir); |
| 324 | } |
| 325 | } |
| 326 | } else { |
| 327 | for (c = gossmap_first_chan(gossmap); |
nothing calls this directly
no test coverage detected