| 2814 | AUTODATA(json_command, &listpeerchannels_command); |
| 2815 | |
| 2816 | struct command_result * |
| 2817 | command_find_channel(struct command *cmd, |
| 2818 | const char *name, |
| 2819 | const char *buffer, const jsmntok_t *tok, |
| 2820 | struct channel **channel) |
| 2821 | { |
| 2822 | struct lightningd *ld = cmd->ld; |
| 2823 | struct channel_id cid; |
| 2824 | struct short_channel_id scid; |
| 2825 | struct peer *peer; |
| 2826 | |
| 2827 | if (json_tok_channel_id(buffer, tok, &cid)) { |
| 2828 | struct peer_node_id_map_iter it; |
| 2829 | |
| 2830 | for (peer = peer_node_id_map_first(ld->peers, &it); |
| 2831 | peer; |
| 2832 | peer = peer_node_id_map_next(ld->peers, &it)) { |
| 2833 | list_for_each(&peer->channels, (*channel), list) { |
| 2834 | if (!channel_state_wants_peercomms((*channel)->state)) |
| 2835 | continue; |
| 2836 | if (channel_id_eq(&(*channel)->cid, &cid)) |
| 2837 | return NULL; |
| 2838 | } |
| 2839 | } |
| 2840 | return command_fail_badparam(cmd, name, buffer, tok, |
| 2841 | "Channel id not found"); |
| 2842 | } else if (json_to_short_channel_id(buffer, tok, &scid)) { |
| 2843 | *channel = any_channel_by_scid(ld, scid, true); |
| 2844 | if (!*channel) |
| 2845 | return command_fail_badparam(cmd, name, buffer, tok, |
| 2846 | "Short channel id not found"); |
| 2847 | return NULL; |
| 2848 | } else { |
| 2849 | return command_fail_badparam(cmd, name, buffer, tok, |
| 2850 | "should be a channel ID or short channel ID"); |
| 2851 | } |
| 2852 | } |
| 2853 | |
| 2854 | static void setup_peer(struct peer *peer) |
| 2855 | { |
no test coverage detected