plugins/topology: use listpeerchannels.

This commit is contained in:
Vincenzo Palazzo
2023-01-12 11:52:10 +10:30
committed by Rusty Russell
parent a56c890ae5
commit c488561282
3 changed files with 14 additions and 21 deletions

View File

@@ -342,4 +342,4 @@ Main web site: <https://github.com/ElementsProject/lightning> Lightning
RFC site (BOLT \#9): RFC site (BOLT \#9):
<https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md> <https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md>
[comment]: # ( SHA256STAMP:adc1f36b764f1d98ba6a34b63f459a19db15fc94e37678806a1eb858a2166167) [comment]: # ( SHA256STAMP:a9e27c78498192757d4972da091715cadd8dbf2f0c08c288e6c600626567f379)

View File

@@ -1915,8 +1915,8 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,
*aliastok = json_get_member(buffer, tok, "alias"), *aliastok = json_get_member(buffer, tok, "alias"),
*max_htlcs = json_get_member(buffer, tok, "max_accepted_htlcs"), *max_htlcs = json_get_member(buffer, tok, "max_accepted_htlcs"),
*htlcstok = json_get_member(buffer, tok, "htlcs"), *htlcstok = json_get_member(buffer, tok, "htlcs"),
*idtok = json_get_member(buffer, tok, "id"), *idtok = json_get_member(buffer, tok, "peer_id"),
*conntok = json_get_member(buffer, tok, "connected"); *conntok = json_get_member(buffer, tok, "peer_connected");
chan = tal(ctx, struct listpeers_channel); chan = tal(ctx, struct listpeers_channel);

View File

@@ -301,25 +301,23 @@ static struct node_map *local_connected(const tal_t *ctx,
const jsmntok_t *result) const jsmntok_t *result)
{ {
size_t i; 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); struct node_map *connected = tal(ctx, struct node_map);
node_map_init(connected); node_map_init(connected);
tal_add_destructor(connected, node_map_clear); tal_add_destructor(connected, node_map_clear);
json_for_each_arr(i, t, peers) { json_for_each_arr(i, channel, channels) {
const jsmntok_t *chans, *c;
struct node_id id; struct node_id id;
bool is_connected, normal_chan; bool is_connected, normal_chan;
const char *err; const char *err;
size_t j;
err = json_scan(tmpctx, buf, t, err = json_scan(tmpctx, buf, channel,
"{id:%,connected:%}", "{peer_id:%,peer_connected:%}",
JSON_SCAN(json_to_node_id, &id), JSON_SCAN(json_to_node_id, &id),
JSON_SCAN(json_to_bool, &is_connected)); JSON_SCAN(json_to_bool, &is_connected));
if (err) if (err)
plugin_err(plugin, "Bad listpeers response (%s): %.*s", plugin_err(plugin, "Bad listpeerchannels response (%s): %.*s",
err, err,
json_tok_full_len(result), json_tok_full_len(result),
json_tok_full(buf, result)); json_tok_full(buf, result));
@@ -328,14 +326,9 @@ static struct node_map *local_connected(const tal_t *ctx,
continue; continue;
/* Must also have a channel in CHANNELD_NORMAL */ /* Must also have a channel in CHANNELD_NORMAL */
normal_chan = false; normal_chan = json_tok_streq(buf,
chans = json_get_member(buf, t, "channels"); json_get_member(buf, channel, "state"),
json_for_each_arr(j, c, chans) { "CHANNELD_NORMAL");
if (json_tok_streq(buf,
json_get_member(buf, c, "state"),
"CHANNELD_NORMAL"))
normal_chan = true;
}
if (normal_chan) if (normal_chan)
node_map_add(connected, node_map_add(connected,
@@ -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! */ /* 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 char *buf,
const jsmntok_t *result, const jsmntok_t *result,
struct listchannels_opts *opts) struct listchannels_opts *opts)
@@ -421,8 +414,8 @@ static struct command_result *json_listchannels(struct command *cmd,
"Can only specify one of " "Can only specify one of "
"`short_channel_id`, " "`short_channel_id`, "
"`source` or `destination`"); "`source` or `destination`");
req = jsonrpc_request_start(cmd->plugin, cmd, "listpeers", req = jsonrpc_request_start(cmd->plugin, cmd, "listpeerchannels",
listpeers_done, forward_error, opts); listpeerchannels_done, forward_error, opts);
return send_outreq(cmd->plugin, req); return send_outreq(cmd->plugin, req);
} }