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

Function json_listpeerchannels

lightningd/peer_control.c:2754–2808  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2752}
2753
2754static struct command_result *json_listpeerchannels(struct command *cmd,
2755 const char *buffer,
2756 const jsmntok_t *obj UNNEEDED,
2757 const jsmntok_t *params)
2758{
2759 struct node_id *peer_id;
2760 struct peer *peer;
2761 struct json_stream *response;
2762 struct short_channel_id *scid;
2763 struct channel_id *cid;
2764
2765 if (!param_check(cmd, buffer, params,
2766 p_opt("id", param_node_id, &peer_id),
2767 p_opt("short_channel_id", param_short_channel_id, &scid),
2768 p_opt("channel_id", param_channel_id, &cid),
2769 NULL))
2770 return command_param_failed();
2771
2772 int count = (peer_id != NULL) + (scid != NULL) + (cid != NULL);
2773 if (count > 1) {
2774 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
2775 "Must not specify more than one of "
2776 "short_channel_id, channel_id or id"
2777 );
2778 }
2779
2780 response = json_stream_success(cmd);
2781 json_array_start(response, "channels");
2782
2783 if (peer_id) {
2784 peer = peer_by_id(cmd->ld, peer_id);
2785 if (peer)
2786 json_add_peerchannels(cmd, response, peer);
2787 } else if (scid) {
2788 const struct channel *c = any_channel_by_scid(cmd->ld, *scid, true);
2789 if (c)
2790 json_add_channel(cmd, response, NULL, c, c->peer);
2791 } else if (cid) {
2792 const struct channel *c = channel_by_cid(cmd->ld, cid);
2793 if (c)
2794 json_add_channel(cmd, response, NULL, c, c->peer);
2795 } else {
2796 struct peer_node_id_map_iter it;
2797
2798 for (peer = peer_node_id_map_first(cmd->ld->peers, &it);
2799 peer;
2800 peer = peer_node_id_map_next(cmd->ld->peers, &it)) {
2801 json_add_peerchannels(cmd, response, peer);
2802 }
2803 }
2804
2805 json_array_end(response);
2806
2807 return command_success(cmd, response);
2808}
2809
2810static const struct json_command listpeerchannels_command = {
2811 "listpeerchannels",

Callers

nothing calls this directly

Calls 11

param_checkFunction · 0.85
json_array_startFunction · 0.85
peer_by_idFunction · 0.85
json_add_peerchannelsFunction · 0.85
json_array_endFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
json_stream_successFunction · 0.70
any_channel_by_scidFunction · 0.70
channel_by_cidFunction · 0.70
command_successFunction · 0.70

Tested by

no test coverage detected