mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
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:
@@ -3302,11 +3302,10 @@ static struct command_result *direct_pay_listpeers(struct command *cmd,
|
||||
d->chan = tal(d, struct short_channel_id_dir);
|
||||
if (chan->scid) {
|
||||
d->chan->scid = *chan->scid;
|
||||
d->chan->dir = *chan->direction;
|
||||
} else {
|
||||
d->chan->scid = *chan->alias[LOCAL];
|
||||
d->chan->dir = 0; /* Don't care. */
|
||||
}
|
||||
d->chan->dir = chan->direction;
|
||||
}
|
||||
|
||||
direct_pay_override(p);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -438,9 +438,10 @@ struct listpeers_channel {
|
||||
bool private;
|
||||
struct bitcoin_txid funding_txid;
|
||||
const char *state;
|
||||
/* scid or alias[LOCAL] is always non-NULL */
|
||||
struct short_channel_id *alias[NUM_SIDES];
|
||||
struct short_channel_id *scid;
|
||||
int *direction;
|
||||
int direction;
|
||||
struct amount_msat total_msat;
|
||||
struct amount_msat spendable_msat;
|
||||
/* TODO Add fields as we need them. */
|
||||
|
||||
Reference in New Issue
Block a user