diff --git a/plugins/libplugin-pay.c b/plugins/libplugin-pay.c index 7584319be..5425811ed 100644 --- a/plugins/libplugin-pay.c +++ b/plugins/libplugin-pay.c @@ -2347,8 +2347,8 @@ REGISTER_PAYMENT_MODIFIER(retry, struct retry_mod_data *, retry_data_init, retry_step_cb); static struct command_result * -local_channel_hints_listpeers(struct command *cmd, const char *buffer, - const jsmntok_t *toks, struct payment *p) +local_channel_hints_listpeerchannels(struct command *cmd, const char *buffer, + const jsmntok_t *toks, struct payment *p) { struct listpeers_channel **chans; @@ -2398,9 +2398,9 @@ static void local_channel_hints_cb(void *d UNUSED, struct payment *p) if (p->parent != NULL || p->step != PAYMENT_STEP_INITIALIZED) return payment_continue(p); - req = jsonrpc_request_start(p->plugin, NULL, "listpeers", - local_channel_hints_listpeers, - local_channel_hints_listpeers, p); + req = jsonrpc_request_start(p->plugin, NULL, "listpeerchannels", + local_channel_hints_listpeerchannels, + local_channel_hints_listpeerchannels, p); send_outreq(p->plugin, req); } @@ -3242,13 +3242,13 @@ static void direct_pay_override(struct payment *p) { payment_continue(p); } -/* Now that we have the listpeers result for the root payment, let's search +/* Now that we have the listpeerchannels result for the root payment, let's search * for a direct channel that is a) connected and b) in state normal. We will * check the capacity based on the channel_hints in the override. */ -static struct command_result *direct_pay_listpeers(struct command *cmd, - const char *buffer, - const jsmntok_t *toks, - struct payment *p) +static struct command_result *direct_pay_listpeerchannels(struct command *cmd, + const char *buffer, + const jsmntok_t *toks, + struct payment *p) { struct listpeers_channel **channels = json_to_listpeers_channels(tmpctx, buffer, toks); struct direct_pay_data *d = payment_mod_directpay_get_data(p); @@ -3289,8 +3289,9 @@ static void direct_pay_cb(struct direct_pay_data *d, struct payment *p) - req = jsonrpc_request_start(p->plugin, NULL, "listpeers", - direct_pay_listpeers, direct_pay_listpeers, + req = jsonrpc_request_start(p->plugin, NULL, "listpeerchannels", + direct_pay_listpeerchannels, + direct_pay_listpeerchannels, p); json_add_node_id(req->js, "id", p->destination); send_outreq(p->plugin, req); diff --git a/plugins/libplugin.c b/plugins/libplugin.c index 55d94aa83..ff01660f2 100644 --- a/plugins/libplugin.c +++ b/plugins/libplugin.c @@ -1914,10 +1914,14 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx, json_get_member(buffer, tok, "spendable_msat"), *aliastok = json_get_member(buffer, tok, "alias"), *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"), + *conntok = json_get_member(buffer, tok, "connected"); chan = tal(ctx, struct listpeers_channel); + json_to_node_id(buffer, idtok, &chan->id); + json_to_bool(buffer, conntok, &chan->connected); json_to_bool(buffer, privtok, &chan->private); chan->state = json_strdup(chan, buffer, statetok); json_to_txid(buffer, ftxidtok, &chan->funding_txid); @@ -1966,44 +1970,24 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx, return chan; } -/* Append channels for this peer */ -static void json_add_listpeers_peer(struct listpeers_channel ***chans, - const char *buffer, - const jsmntok_t *tok) -{ - size_t i; - const jsmntok_t *iter; - const jsmntok_t *idtok = json_get_member(buffer, tok, "id"), - *conntok = json_get_member(buffer, tok, "connected"), - *channelstok = json_get_member(buffer, tok, "channels"); - bool connected; - struct node_id id; - - json_to_node_id(buffer, idtok, &id); - json_to_bool(buffer, conntok, &connected); - - 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); - } -} - struct listpeers_channel **json_to_listpeers_channels(const tal_t *ctx, const char *buffer, const jsmntok_t *tok) { size_t i; const jsmntok_t *iter; - const jsmntok_t *peerstok = json_get_member(buffer, tok, "peers"); + const jsmntok_t *channelstok = json_get_member(buffer, tok, "channels"); struct listpeers_channel **chans; chans = tal_arr(ctx, struct listpeers_channel *, 0); - json_for_each_arr(i, iter, peerstok) - json_add_listpeers_peer(&chans, buffer, iter); + json_for_each_arr(i, iter, channelstok) { + struct listpeers_channel *chan; + + chan = json_to_listpeers_channel(chans, buffer, iter); + if (!chan) + continue; + tal_arr_expand(&chans, chan); + } return chans; } diff --git a/plugins/libplugin.h b/plugins/libplugin.h index 987406151..ce15ce34f 100644 --- a/plugins/libplugin.h +++ b/plugins/libplugin.h @@ -449,7 +449,7 @@ struct listpeers_channel { /* TODO Add fields as we need them. */ }; -/* Returns an array of listpeers_channel * */ +/* Returns an array of listpeers_channel from listpeerchannels * */ struct listpeers_channel **json_to_listpeers_channels(const tal_t *ctx, const char *buffer, const jsmntok_t *tok);