mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
plugins: use listpeerchannels instead of listpeers.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -2347,8 +2347,8 @@ REGISTER_PAYMENT_MODIFIER(retry, struct retry_mod_data *, retry_data_init,
|
|||||||
retry_step_cb);
|
retry_step_cb);
|
||||||
|
|
||||||
static struct command_result *
|
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)
|
const jsmntok_t *toks, struct payment *p)
|
||||||
{
|
{
|
||||||
struct listpeers_channel **chans;
|
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)
|
if (p->parent != NULL || p->step != PAYMENT_STEP_INITIALIZED)
|
||||||
return payment_continue(p);
|
return payment_continue(p);
|
||||||
|
|
||||||
req = jsonrpc_request_start(p->plugin, NULL, "listpeers",
|
req = jsonrpc_request_start(p->plugin, NULL, "listpeerchannels",
|
||||||
local_channel_hints_listpeers,
|
local_channel_hints_listpeerchannels,
|
||||||
local_channel_hints_listpeers, p);
|
local_channel_hints_listpeerchannels, p);
|
||||||
send_outreq(p->plugin, req);
|
send_outreq(p->plugin, req);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3242,13 +3242,13 @@ static void direct_pay_override(struct payment *p) {
|
|||||||
payment_continue(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
|
* 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. */
|
* 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 char *buffer,
|
||||||
const jsmntok_t *toks,
|
const jsmntok_t *toks,
|
||||||
struct payment *p)
|
struct payment *p)
|
||||||
{
|
{
|
||||||
struct listpeers_channel **channels = json_to_listpeers_channels(tmpctx, buffer, toks);
|
struct listpeers_channel **channels = json_to_listpeers_channels(tmpctx, buffer, toks);
|
||||||
struct direct_pay_data *d = payment_mod_directpay_get_data(p);
|
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",
|
req = jsonrpc_request_start(p->plugin, NULL, "listpeerchannels",
|
||||||
direct_pay_listpeers, direct_pay_listpeers,
|
direct_pay_listpeerchannels,
|
||||||
|
direct_pay_listpeerchannels,
|
||||||
p);
|
p);
|
||||||
json_add_node_id(req->js, "id", p->destination);
|
json_add_node_id(req->js, "id", p->destination);
|
||||||
send_outreq(p->plugin, req);
|
send_outreq(p->plugin, req);
|
||||||
|
|||||||
@@ -1914,10 +1914,14 @@ static struct listpeers_channel *json_to_listpeers_channel(const tal_t *ctx,
|
|||||||
json_get_member(buffer, tok, "spendable_msat"),
|
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"),
|
*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);
|
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);
|
json_to_bool(buffer, privtok, &chan->private);
|
||||||
chan->state = json_strdup(chan, buffer, statetok);
|
chan->state = json_strdup(chan, buffer, statetok);
|
||||||
json_to_txid(buffer, ftxidtok, &chan->funding_txid);
|
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;
|
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,
|
struct listpeers_channel **json_to_listpeers_channels(const tal_t *ctx,
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
const jsmntok_t *tok)
|
const jsmntok_t *tok)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
const jsmntok_t *iter;
|
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;
|
struct listpeers_channel **chans;
|
||||||
|
|
||||||
chans = tal_arr(ctx, struct listpeers_channel *, 0);
|
chans = tal_arr(ctx, struct listpeers_channel *, 0);
|
||||||
json_for_each_arr(i, iter, peerstok)
|
json_for_each_arr(i, iter, channelstok) {
|
||||||
json_add_listpeers_peer(&chans, buffer, iter);
|
struct listpeers_channel *chan;
|
||||||
|
|
||||||
|
chan = json_to_listpeers_channel(chans, buffer, iter);
|
||||||
|
if (!chan)
|
||||||
|
continue;
|
||||||
|
tal_arr_expand(&chans, chan);
|
||||||
|
}
|
||||||
return chans;
|
return chans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ struct listpeers_channel {
|
|||||||
/* TODO Add fields as we need them. */
|
/* 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,
|
struct listpeers_channel **json_to_listpeers_channels(const tal_t *ctx,
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
const jsmntok_t *tok);
|
const jsmntok_t *tok);
|
||||||
|
|||||||
Reference in New Issue
Block a user