MCPcopy Create free account
hub / github.com/ElementsProject/lightning / json_setchannel

Function json_setchannel

lightningd/peer_control.c:2684–2743  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2682AUTODATA(json_command, &setchannelfee_command);
2683
2684static struct command_result *json_setchannel(struct command *cmd,
2685 const char *buffer,
2686 const jsmntok_t *obj UNNEEDED,
2687 const jsmntok_t *params)
2688{
2689 struct json_stream *response;
2690 struct peer *peer;
2691 struct channel **channels;
2692 u32 *base, *ppm, *delaysecs;
2693 struct amount_msat *htlc_min, *htlc_max;
2694
2695 /* Parse the JSON command */
2696 if (!param(cmd, buffer, params,
2697 p_req("id", param_channel_or_all, &channels),
2698 p_opt("feebase", param_msat_u32, &base),
2699 p_opt("feeppm", param_number, &ppm),
2700 p_opt("htlcmin", param_msat, &htlc_min),
2701 p_opt("htlcmax", param_msat, &htlc_max),
2702 p_opt_def("enforcedelay", param_number, &delaysecs, 600),
2703 NULL))
2704 return command_param_failed();
2705
2706 /* Prevent obviously incorrect things! */
2707 if (htlc_min && htlc_max
2708 && amount_msat_less(*htlc_max, *htlc_min)) {
2709 return command_fail(cmd, LIGHTNINGD,
2710 "htlcmax cannot be less than htlcmin");
2711 }
2712
2713 /* Open JSON response object for later iteration */
2714 response = json_stream_success(cmd);
2715 json_array_start(response, "channels");
2716
2717 /* If the users requested 'all' channels we need to iterate */
2718 if (channels == NULL) {
2719 list_for_each(&cmd->ld->peers, peer, list) {
2720 struct channel *channel;
2721 list_for_each(&peer->channels, channel, list) {
2722 if (channel->state != CHANNELD_NORMAL &&
2723 channel->state != CHANNELD_AWAITING_LOCKIN &&
2724 channel->state != DUALOPEND_AWAITING_LOCKIN)
2725 continue;
2726 set_channel_config(cmd, channel, base, ppm,
2727 htlc_min, htlc_max,
2728 *delaysecs, response, true);
2729 }
2730 }
2731 /* single peer should be updated */
2732 } else {
2733 for (size_t i = 0; i < tal_count(channels); i++) {
2734 set_channel_config(cmd, channels[i], base, ppm,
2735 htlc_min, htlc_max,
2736 *delaysecs, response, true);
2737 }
2738 }
2739
2740 /* Close and return response */
2741 json_array_end(response);

Callers

nothing calls this directly

Calls 9

amount_msat_lessFunction · 0.85
set_channel_configFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
json_stream_successFunction · 0.70
command_successFunction · 0.70
paramFunction · 0.50
json_array_startFunction · 0.50
json_array_endFunction · 0.50

Tested by

no test coverage detected