| 2752 | } |
| 2753 | |
| 2754 | static struct command_result *json_listpeerchannels(struct command *cmd, |
| 2755 | const char *buffer, |
| 2756 | const jsmntok_t *obj UNNEEDED, |
| 2757 | const jsmntok_t *params) |
| 2758 | { |
| 2759 | struct node_id *peer_id; |
| 2760 | struct peer *peer; |
| 2761 | struct json_stream *response; |
| 2762 | struct short_channel_id *scid; |
| 2763 | struct channel_id *cid; |
| 2764 | |
| 2765 | if (!param_check(cmd, buffer, params, |
| 2766 | p_opt("id", param_node_id, &peer_id), |
| 2767 | p_opt("short_channel_id", param_short_channel_id, &scid), |
| 2768 | p_opt("channel_id", param_channel_id, &cid), |
| 2769 | NULL)) |
| 2770 | return command_param_failed(); |
| 2771 | |
| 2772 | int count = (peer_id != NULL) + (scid != NULL) + (cid != NULL); |
| 2773 | if (count > 1) { |
| 2774 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2775 | "Must not specify more than one of " |
| 2776 | "short_channel_id, channel_id or id" |
| 2777 | ); |
| 2778 | } |
| 2779 | |
| 2780 | response = json_stream_success(cmd); |
| 2781 | json_array_start(response, "channels"); |
| 2782 | |
| 2783 | if (peer_id) { |
| 2784 | peer = peer_by_id(cmd->ld, peer_id); |
| 2785 | if (peer) |
| 2786 | json_add_peerchannels(cmd, response, peer); |
| 2787 | } else if (scid) { |
| 2788 | const struct channel *c = any_channel_by_scid(cmd->ld, *scid, true); |
| 2789 | if (c) |
| 2790 | json_add_channel(cmd, response, NULL, c, c->peer); |
| 2791 | } else if (cid) { |
| 2792 | const struct channel *c = channel_by_cid(cmd->ld, cid); |
| 2793 | if (c) |
| 2794 | json_add_channel(cmd, response, NULL, c, c->peer); |
| 2795 | } else { |
| 2796 | struct peer_node_id_map_iter it; |
| 2797 | |
| 2798 | for (peer = peer_node_id_map_first(cmd->ld->peers, &it); |
| 2799 | peer; |
| 2800 | peer = peer_node_id_map_next(cmd->ld->peers, &it)) { |
| 2801 | json_add_peerchannels(cmd, response, peer); |
| 2802 | } |
| 2803 | } |
| 2804 | |
| 2805 | json_array_end(response); |
| 2806 | |
| 2807 | return command_success(cmd, response); |
| 2808 | } |
| 2809 | |
| 2810 | static const struct json_command listpeerchannels_command = { |
| 2811 | "listpeerchannels", |
nothing calls this directly
no test coverage detected