pay: use json_to_listpeers_channels() for local_channel_hints.

Don't parse the listpeers.channels output ourselves: with two extra fields
we can simply reuse json_to_listpeers_channels().

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

View File

@@ -1912,7 +1912,9 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,
*tmsattok = json_get_member(buffer, tok, "total_msat"),
*smsattok =
json_get_member(buffer, tok, "spendable_msat"),
*aliastok = json_get_member(buffer, tok, "alias");
*aliastok = json_get_member(buffer, tok, "alias"),
*max_htlcs = json_get_member(buffer, tok, "max_accepted_htlcs"),
*htlcstok = json_get_member(buffer, tok, "htlcs");
chan = tal(ctx, struct listpeers_channel);
@@ -1958,6 +1960,8 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,
json_to_int(buffer, dirtok, &chan->direction);
json_to_msat(buffer, tmsattok, &chan->total_msat);
json_to_msat(buffer, smsattok, &chan->spendable_msat);
json_to_u16(buffer, max_htlcs, &chan->max_accepted_htlcs);
chan->num_htlcs = htlcstok->size;
return chan;
}
@@ -1998,7 +2002,7 @@ struct listpeers_channel **json_to_listpeers_channels(const tal_t *ctx,
struct listpeers_channel **chans;
chans = tal_arr(ctx, struct listpeers_channel *, 0);
json_for_each_obj(i, iter, peerstok)
json_for_each_arr(i, iter, peerstok)
json_add_listpeers_peer(&chans, buffer, iter);
return chans;
}