libplugin: don't return unopened channels from json_to_listpeers_channels().

This way we always have an SCID and a direction.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-01-12 11:49:10 +10:30
parent 57dcf68c0b
commit 5d5b9c6812
3 changed files with 11 additions and 11 deletions

View File

@@ -1925,14 +1925,6 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,
json_to_short_channel_id(buffer, scidtok, chan->scid);
} else {
chan->scid = NULL;
chan->direction = NULL;
}
if (dirtok != NULL) {
chan->direction = tal(chan, int);
json_to_int(buffer, dirtok, chan->direction);
} else {
chan->direction = NULL;
}
if (aliastok != NULL) {
@@ -1958,6 +1950,12 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,
chan->alias[REMOTE] = NULL;
}
/* If we catch a channel during opening, these might not be set.
* It's not a real channel (yet), so ignore it! */
if (!chan->scid && !chan->alias[LOCAL])
return tal_free(chan);
json_to_int(buffer, dirtok, &chan->direction);
json_to_msat(buffer, tmsattok, &chan->total_msat);
json_to_msat(buffer, smsattok, &chan->spendable_msat);
@@ -1982,6 +1980,8 @@ static void json_add_listpeers_peer(struct listpeers_channel ***chans,
json_for_each_arr(i, iter, channelstok) {
struct listpeers_channel *chan = json_to_listpeers_channel(*chans, buffer, iter);
if (!chan)
continue;
chan->id = id;
chan->connected = connected;
tal_arr_expand(chans, chan);