plugins: use listpeerchannels instead of listpeers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2023-01-12 11:51:10 +10:30
parent ff2d7e6833
commit a56c890ae5
3 changed files with 28 additions and 43 deletions

View File

@@ -2347,7 +2347,7 @@ 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,
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,10 +3242,10 @@ 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,
static struct command_result *direct_pay_listpeerchannels(struct command *cmd,
const char *buffer,
const jsmntok_t *toks,
struct payment *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);

View File

@@ -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;
}

View File

@@ -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);