From 4122f955c1cdb58736650bc25942a1793e734b68 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 17 Jan 2019 10:06:40 +1030 Subject: [PATCH] plugins/pay: simplify listpeers_done code a little. Avoid the unnecessary extra var, and don't use "capacity" since that usually refers to static capacity. Reported-by: @cdecker Signed-off-by: Rusty Russell --- plugins/pay.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/pay.c b/plugins/pay.c index 627c91bac..30b614d8d 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -694,8 +694,8 @@ static struct command_result *listpeers_done(struct command *cmd, chan = json_get_member(buf, peer, "channels"); chans_end = json_next(chan); for (chan = chan + 1; chan < chans_end; chan = json_next(chan)) { - const jsmntok_t *state, *spendable, *scid, *dir; - u64 capacity; + const jsmntok_t *state, *scid, *dir; + u64 spendable; /* gossipd will only consider things in state NORMAL * anyway; we don't need to exclude others. */ @@ -703,11 +703,12 @@ static struct command_result *listpeers_done(struct command *cmd, if (!json_tok_streq(buf, state, "CHANNELD_NORMAL")) continue; - spendable = json_get_member(buf, chan, - "spendable_msatoshi"); - json_to_u64(buf, spendable, &capacity); + json_to_u64(buf, + json_get_member(buf, chan, + "spendable_msatoshi"), + &spendable); - if (connected && capacity >= pc->msatoshi) + if (connected && spendable >= pc->msatoshi) continue; /* Exclude this disconnected or low-capacity channel */ @@ -722,7 +723,7 @@ static struct command_result *listpeers_done(struct command *cmd, tal_append_fmt(&mods, "Excluded channel %s (%"PRIu64" msat, %s). ", pc->excludes[tal_count(pc->excludes)-1], - capacity, + spendable, connected ? "connected" : "disconnected"); } }