| 2070 | } |
| 2071 | |
| 2072 | static struct command_result *listpeerchannels_get_result(struct command *cmd, |
| 2073 | const char *methodname, |
| 2074 | const char *buf, |
| 2075 | const jsmntok_t *toks, |
| 2076 | struct splice_cmd *splice_cmd) |
| 2077 | { |
| 2078 | struct splice_script_error *error; |
| 2079 | struct splice_script_chan **channels; |
| 2080 | struct command_result *result; |
| 2081 | const jsmntok_t *jchannels, *jchannel; |
| 2082 | char **lines; |
| 2083 | struct json_stream *response; |
| 2084 | const char *str; |
| 2085 | size_t i; |
| 2086 | const char *err; |
| 2087 | |
| 2088 | channels = tal_arr(tmpctx, struct splice_script_chan*, 0); |
| 2089 | jchannels = json_get_member(buf, toks, "channels"); |
| 2090 | json_for_each_arr(i, jchannel, jchannels) { |
| 2091 | tal_arr_expand(&channels, tal(channels, |
| 2092 | struct splice_script_chan)); |
| 2093 | |
| 2094 | err = json_scan(tmpctx, buf, jchannel, |
| 2095 | "{peer_id?:%,channel_id?:%}", |
| 2096 | JSON_SCAN(json_to_node_id, |
| 2097 | &channels[i]->node_id), |
| 2098 | JSON_SCAN(json_to_channel_id, |
| 2099 | &channels[i]->chan_id)); |
| 2100 | if (err) |
| 2101 | errx(1, "Bad listpeerchannels.channels %zu: %s", |
| 2102 | i, err); |
| 2103 | } |
| 2104 | |
| 2105 | if (splice_cmd->script) { |
| 2106 | error = parse_splice_script(splice_cmd, splice_cmd->script, |
| 2107 | channels, &splice_cmd->actions); |
| 2108 | if (error) { |
| 2109 | response = jsonrpc_stream_fail(cmd, |
| 2110 | JSONRPC2_INVALID_PARAMS, |
| 2111 | "Splice script compile" |
| 2112 | " failed"); |
| 2113 | |
| 2114 | json_array_start(response, "compiler_error"); |
| 2115 | |
| 2116 | str = fmt_splice_script_compiler_error(response, |
| 2117 | splice_cmd->script, |
| 2118 | error); |
| 2119 | lines = tal_strsplit(response, take(str), "\n", |
| 2120 | STR_NO_EMPTY); |
| 2121 | for (i = 0; lines[i] != NULL; i++) |
| 2122 | json_add_string(response, NULL, lines[i]); |
| 2123 | json_array_end(response); |
| 2124 | return command_finished(cmd, response); |
| 2125 | } |
| 2126 | |
| 2127 | splice_cmd->states = tal_arr(splice_cmd, |
| 2128 | struct splice_cmd_action_state*, |
| 2129 | tal_count(splice_cmd->actions)); |
nothing calls this directly
no test coverage detected