| 2610 | } |
| 2611 | |
| 2612 | static struct command_result *json_setchannelfee(struct command *cmd, |
| 2613 | const char *buffer, |
| 2614 | const jsmntok_t *obj UNNEEDED, |
| 2615 | const jsmntok_t *params) |
| 2616 | { |
| 2617 | struct json_stream *response; |
| 2618 | struct peer *peer; |
| 2619 | struct channel **channels; |
| 2620 | u32 *base, *ppm, *delaysecs; |
| 2621 | |
| 2622 | /* Parse the JSON command */ |
| 2623 | if (!param(cmd, buffer, params, |
| 2624 | p_req("id", param_channel_or_all, &channels), |
| 2625 | p_opt_def("base", param_msat_u32, |
| 2626 | &base, cmd->ld->config.fee_base), |
| 2627 | p_opt_def("ppm", param_number, &ppm, |
| 2628 | cmd->ld->config.fee_per_satoshi), |
| 2629 | /* BOLT #7: |
| 2630 | * If it creates a new `channel_update` with updated channel parameters: |
| 2631 | * - SHOULD keep accepting the previous channel parameters for 10 minutes |
| 2632 | */ |
| 2633 | p_opt_def("enforcedelay", param_number, &delaysecs, 600), |
| 2634 | NULL)) |
| 2635 | return command_param_failed(); |
| 2636 | |
| 2637 | /* Open JSON response object for later iteration */ |
| 2638 | response = json_stream_success(cmd); |
| 2639 | json_add_num(response, "base", *base); |
| 2640 | json_add_num(response, "ppm", *ppm); |
| 2641 | json_array_start(response, "channels"); |
| 2642 | |
| 2643 | /* If the users requested 'all' channels we need to iterate */ |
| 2644 | if (channels == NULL) { |
| 2645 | list_for_each(&cmd->ld->peers, peer, list) { |
| 2646 | struct channel *channel; |
| 2647 | list_for_each(&peer->channels, channel, list) { |
| 2648 | if (channel->state != CHANNELD_NORMAL && |
| 2649 | channel->state != CHANNELD_AWAITING_LOCKIN && |
| 2650 | channel->state != DUALOPEND_AWAITING_LOCKIN) |
| 2651 | continue; |
| 2652 | set_channel_config(cmd, channel, base, ppm, NULL, NULL, |
| 2653 | *delaysecs, response, false); |
| 2654 | } |
| 2655 | } |
| 2656 | /* single peer should be updated */ |
| 2657 | } else { |
| 2658 | for (size_t i = 0; i < tal_count(channels); i++) { |
| 2659 | set_channel_config(cmd, channels[i], base, ppm, NULL, NULL, |
| 2660 | *delaysecs, response, false); |
| 2661 | } |
| 2662 | } |
| 2663 | |
| 2664 | /* Close and return response */ |
| 2665 | json_array_end(response); |
| 2666 | return command_success(cmd, response); |
| 2667 | } |
| 2668 | |
| 2669 | static const struct json_command setchannelfee_command = { |
nothing calls this directly
no test coverage detected