| 2029 | |
| 2030 | |
| 2031 | struct command_result * |
| 2032 | command_find_channel(struct command *cmd, |
| 2033 | const char *buffer, const jsmntok_t *tok, |
| 2034 | struct channel **channel) |
| 2035 | { |
| 2036 | struct lightningd *ld = cmd->ld; |
| 2037 | struct channel_id cid; |
| 2038 | struct short_channel_id scid; |
| 2039 | struct peer *peer; |
| 2040 | |
| 2041 | if (json_tok_channel_id(buffer, tok, &cid)) { |
| 2042 | list_for_each(&ld->peers, peer, list) { |
| 2043 | list_for_each(&peer->channels, (*channel), list) { |
| 2044 | if (!channel_active(*channel)) |
| 2045 | continue; |
| 2046 | if (channel_id_eq(&(*channel)->cid, &cid)) |
| 2047 | return NULL; |
| 2048 | } |
| 2049 | } |
| 2050 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2051 | "Channel ID not found: '%.*s'", |
| 2052 | tok->end - tok->start, |
| 2053 | buffer + tok->start); |
| 2054 | } else if (json_to_short_channel_id(buffer, tok, &scid)) { |
| 2055 | *channel = any_channel_by_scid(ld, &scid, true); |
| 2056 | if (!*channel) |
| 2057 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2058 | "Short channel ID not found: '%.*s'", |
| 2059 | tok->end - tok->start, |
| 2060 | buffer + tok->start); |
| 2061 | if (!channel_active(*channel)) |
| 2062 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 2063 | "Short channel ID not active: '%.*s'", |
| 2064 | tok->end - tok->start, |
| 2065 | buffer + tok->start); |
| 2066 | return NULL; |
| 2067 | } else { |
| 2068 | return command_fail_badparam(cmd, "id", buffer, tok, |
| 2069 | "should be a channel ID or short channel ID"); |
| 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | static void setup_peer(struct peer *peer, u32 delay) |
| 2074 | { |
no test coverage detected