Skip to content

Commit

Permalink
plugins/topology: use listpeerchannels.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzopalazzo authored and rustyrussell committed Jan 13, 2023
1 parent a56c890 commit c488561
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion doc/lightning-listpeerchannels.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,4 @@ Main web site: <https://github.com/ElementsProject/lightning> Lightning
RFC site (BOLT \#9):
<https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md>

[comment]: # ( SHA256STAMP:adc1f36b764f1d98ba6a34b63f459a19db15fc94e37678806a1eb858a2166167)
[comment]: # ( SHA256STAMP:a9e27c78498192757d4972da091715cadd8dbf2f0c08c288e6c600626567f379)
4 changes: 2 additions & 2 deletions plugins/libplugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1915,8 +1915,8 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,
*aliastok = json_get_member(buffer, tok, "alias"),
*max_htlcs = json_get_member(buffer, tok, "max_accepted_htlcs"),
*htlcstok = json_get_member(buffer, tok, "htlcs"),
*idtok = json_get_member(buffer, tok, "id"),
*conntok = json_get_member(buffer, tok, "connected");
*idtok = json_get_member(buffer, tok, "peer_id"),
*conntok = json_get_member(buffer, tok, "peer_connected");

chan = tal(ctx, struct listpeers_channel);

Expand Down
29 changes: 11 additions & 18 deletions plugins/topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,25 +301,23 @@ static struct node_map *local_connected(const tal_t *ctx,
const jsmntok_t *result)
{
size_t i;
const jsmntok_t *t, *peers = json_get_member(buf, result, "peers");
const jsmntok_t *channel, *channels = json_get_member(buf, result, "channels");
struct node_map *connected = tal(ctx, struct node_map);

node_map_init(connected);
tal_add_destructor(connected, node_map_clear);

json_for_each_arr(i, t, peers) {
const jsmntok_t *chans, *c;
json_for_each_arr(i, channel, channels) {
struct node_id id;
bool is_connected, normal_chan;
const char *err;
size_t j;

err = json_scan(tmpctx, buf, t,
"{id:%,connected:%}",
err = json_scan(tmpctx, buf, channel,
"{peer_id:%,peer_connected:%}",
JSON_SCAN(json_to_node_id, &id),
JSON_SCAN(json_to_bool, &is_connected));
if (err)
plugin_err(plugin, "Bad listpeers response (%s): %.*s",
plugin_err(plugin, "Bad listpeerchannels response (%s): %.*s",
err,
json_tok_full_len(result),
json_tok_full(buf, result));
Expand All @@ -328,14 +326,9 @@ static struct node_map *local_connected(const tal_t *ctx,
continue;

/* Must also have a channel in CHANNELD_NORMAL */
normal_chan = false;
chans = json_get_member(buf, t, "channels");
json_for_each_arr(j, c, chans) {
if (json_tok_streq(buf,
json_get_member(buf, c, "state"),
"CHANNELD_NORMAL"))
normal_chan = true;
}
normal_chan = json_tok_streq(buf,
json_get_member(buf, channel, "state"),
"CHANNELD_NORMAL");

if (normal_chan)
node_map_add(connected,
Expand All @@ -346,7 +339,7 @@ static struct node_map *local_connected(const tal_t *ctx,
}

/* We want to combine local knowledge to we know which are actually inactive! */
static struct command_result *listpeers_done(struct command *cmd,
static struct command_result *listpeerchannels_done(struct command *cmd,
const char *buf,
const jsmntok_t *result,
struct listchannels_opts *opts)
Expand Down Expand Up @@ -421,8 +414,8 @@ static struct command_result *json_listchannels(struct command *cmd,
"Can only specify one of "
"`short_channel_id`, "
"`source` or `destination`");
req = jsonrpc_request_start(cmd->plugin, cmd, "listpeers",
listpeers_done, forward_error, opts);
req = jsonrpc_request_start(cmd->plugin, cmd, "listpeerchannels",
listpeerchannels_done, forward_error, opts);
return send_outreq(cmd->plugin, req);
}

Expand Down

0 comments on commit c488561

Please sign in to comment.