| 3913 | } |
| 3914 | |
| 3915 | static struct command_result *json_setchannel(struct command *cmd, |
| 3916 | const char *buffer, |
| 3917 | const jsmntok_t *obj UNNEEDED, |
| 3918 | const jsmntok_t *params) |
| 3919 | { |
| 3920 | struct json_stream *response; |
| 3921 | struct peer *peer; |
| 3922 | struct channel **channels; |
| 3923 | u32 *base, *ppm, *delaysecs; |
| 3924 | struct amount_msat *htlc_min, *htlc_max; |
| 3925 | bool *ignore_fee_limits; |
| 3926 | |
| 3927 | /* Parse the JSON command */ |
| 3928 | if (!param_check(cmd, buffer, params, |
| 3929 | p_req("id", param_channel_or_all, &channels), |
| 3930 | p_opt("feebase", param_msat_u32, &base), |
| 3931 | p_opt("feeppm", param_number, &ppm), |
| 3932 | p_opt("htlcmin", param_msat, &htlc_min), |
| 3933 | p_opt("htlcmax", param_msat, &htlc_max), |
| 3934 | p_opt_def("enforcedelay", param_number, &delaysecs, 600), |
| 3935 | p_opt("ignorefeelimits", param_bool, &ignore_fee_limits), |
| 3936 | NULL)) |
| 3937 | return command_param_failed(); |
| 3938 | |
| 3939 | /* Prevent obviously incorrect things! */ |
| 3940 | if (htlc_min && htlc_max |
| 3941 | && amount_msat_less(*htlc_max, *htlc_min)) { |
| 3942 | return command_fail(cmd, LIGHTNINGD, |
| 3943 | "htlcmax cannot be less than htlcmin"); |
| 3944 | } |
| 3945 | |
| 3946 | if (command_check_only(cmd)) |
| 3947 | return command_check_done(cmd); |
| 3948 | |
| 3949 | /* Open JSON response object for later iteration */ |
| 3950 | response = json_stream_success(cmd); |
| 3951 | json_array_start(response, "channels"); |
| 3952 | |
| 3953 | /* If the users requested 'all' channels we need to iterate */ |
| 3954 | if (channels == NULL) { |
| 3955 | struct peer_node_id_map_iter it; |
| 3956 | |
| 3957 | for (peer = peer_node_id_map_first(cmd->ld->peers, &it); |
| 3958 | peer; |
| 3959 | peer = peer_node_id_map_next(cmd->ld->peers, &it)) { |
| 3960 | struct channel *channel; |
| 3961 | list_for_each(&peer->channels, channel, list) { |
| 3962 | /* cppcheck-suppress uninitvar - false positive on channel */ |
| 3963 | if (!channel_state_can_setchannel(channel->state)) |
| 3964 | continue; |
| 3965 | set_channel_config(cmd, channel, base, ppm, |
| 3966 | htlc_min, htlc_max, |
| 3967 | *delaysecs, ignore_fee_limits, |
| 3968 | response); |
| 3969 | } |
| 3970 | } |
| 3971 | /* single peer should be updated */ |
| 3972 | } else { |
nothing calls this directly
no test coverage detected