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

Function param_channel_or_all

lightningd/peer_control.c:3542–3584  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3540}
3541
3542static struct command_result *param_channel_or_all(struct command *cmd,
3543 const char *name,
3544 const char *buffer,
3545 const jsmntok_t *tok,
3546 struct channel ***channels)
3547{
3548 struct command_result *res;
3549 struct peer *peer;
3550 struct channel *channel;
3551
3552 *channels = tal_arr(cmd, struct channel *, 0);
3553
3554 /* early return the easy case */
3555 if (json_tok_streq(buffer, tok, "all")) {
3556 *channels = tal_free(*channels);
3557 return NULL;
3558 }
3559
3560 /* Find channels by peer_id */
3561 peer = peer_from_json(cmd->ld, buffer, tok);
3562 if (peer) {
3563 list_for_each(&peer->channels, channel, list) {
3564 if (channel_state_can_setchannel(channel->state))
3565 tal_arr_expand(channels, channel);
3566 }
3567 if (tal_count(*channels) == 0)
3568 return command_fail(cmd, LIGHTNINGD,
3569 "Could not find any active channels of peer with that id");
3570 return NULL;
3571 }
3572
3573 /* Find channel by id or scid */
3574 res = command_find_channel(cmd, name, buffer, tok, &channel);
3575 if (res)
3576 return res;
3577 /* check channel is found and in valid state */
3578 if (!channel_state_can_setchannel(channel->state))
3579 return command_fail_badparam(cmd, name, buffer, tok,
3580 tal_fmt(tmpctx, "Channel in state %s",
3581 channel_state_name(channel)));
3582 tal_arr_expand(channels, channel);
3583 return NULL;
3584}
3585
3586/* Fee base is a u32, but it's convenient to let them specify it using
3587 * msat etc. suffix. */

Callers

nothing calls this directly

Calls 8

json_tok_streqFunction · 0.85
tal_freeFunction · 0.85
peer_from_jsonFunction · 0.85
command_find_channelFunction · 0.85
command_failFunction · 0.70
channel_state_nameFunction · 0.70
command_fail_badparamFunction · 0.50

Tested by

no test coverage detected