mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 14:42:40 +01:00
lightningd: prepare internal json routines for listpeerchannels.
We're soon going to call json_add_unsaved_channel and json_add_uncommitted_channel from a new place, where we want the peer state directly included. Based on patch by @vincenzopalazzo. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
300f732bbe
commit
1d8b899551
7 changed files with 44 additions and 12 deletions
|
@ -105,7 +105,9 @@ static void channel_err_broken(struct channel *channel,
|
|||
}
|
||||
|
||||
void json_add_unsaved_channel(struct json_stream *response,
|
||||
const struct channel *channel)
|
||||
const struct channel *channel,
|
||||
/* Only set for listpeerchannels */
|
||||
const struct peer *peer)
|
||||
{
|
||||
struct amount_msat total;
|
||||
struct open_attempt *oa;
|
||||
|
@ -125,6 +127,11 @@ void json_add_unsaved_channel(struct json_stream *response,
|
|||
oa = channel->open_attempt;
|
||||
|
||||
json_object_start(response, NULL);
|
||||
/* listpeerchannels only */
|
||||
if (peer) {
|
||||
json_add_node_id(response, "peer_id", &peer->id);
|
||||
json_add_bool(response, "peer_connected", peer->connected == PEER_CONNECTED);
|
||||
}
|
||||
json_add_string(response, "state", channel_state_name(channel));
|
||||
json_add_string(response, "owner", channel->owner->name);
|
||||
json_add_string(response, "opener", channel->opener == LOCAL ?
|
||||
|
|
|
@ -22,7 +22,9 @@ void dualopen_tell_depth(struct subd *dualopend,
|
|||
void channel_unsaved_close_conn(struct channel *channel, const char *why);
|
||||
|
||||
void json_add_unsaved_channel(struct json_stream *response,
|
||||
const struct channel *channel);
|
||||
const struct channel *channel,
|
||||
/* Only set for listpeerchannels */
|
||||
const struct peer *peer);
|
||||
|
||||
void channel_update_reserve(struct channel *channel,
|
||||
struct channel_config *their_config,
|
||||
|
|
|
@ -32,9 +32,12 @@
|
|||
#include <wally_psbt.h>
|
||||
|
||||
void json_add_uncommitted_channel(struct json_stream *response,
|
||||
const struct uncommitted_channel *uc)
|
||||
const struct uncommitted_channel *uc,
|
||||
/* Only set for listpeerchannels */
|
||||
const struct peer *peer)
|
||||
{
|
||||
struct amount_msat total, ours;
|
||||
|
||||
if (!uc)
|
||||
return;
|
||||
|
||||
|
@ -43,6 +46,10 @@ void json_add_uncommitted_channel(struct json_stream *response,
|
|||
return;
|
||||
|
||||
json_object_start(response, NULL);
|
||||
if (peer) {
|
||||
json_add_node_id(response, "peer_id", &peer->id);
|
||||
json_add_bool(response, "peer_connected", peer->connected == PEER_CONNECTED);
|
||||
}
|
||||
json_add_string(response, "state", "OPENINGD");
|
||||
json_add_string(response, "owner", "lightning_openingd");
|
||||
json_add_string(response, "opener", "local");
|
||||
|
|
|
@ -12,7 +12,9 @@ struct peer_fd;
|
|||
struct uncommitted_channel;
|
||||
|
||||
void json_add_uncommitted_channel(struct json_stream *response,
|
||||
const struct uncommitted_channel *uc);
|
||||
const struct uncommitted_channel *uc,
|
||||
/* Only set for listpeerchannels */
|
||||
const struct peer *peer);
|
||||
|
||||
bool peer_start_openingd(struct peer *peer,
|
||||
struct peer_fd *peer_fd);
|
||||
|
|
|
@ -695,7 +695,9 @@ struct amount_msat channel_amount_receivable(const struct channel *channel)
|
|||
|
||||
static void json_add_channel(struct lightningd *ld,
|
||||
struct json_stream *response, const char *key,
|
||||
const struct channel *channel)
|
||||
const struct channel *channel,
|
||||
/* Only set for listpeerchannels */
|
||||
const struct peer *peer)
|
||||
{
|
||||
struct channel_stats channel_stats;
|
||||
struct amount_msat funding_msat;
|
||||
|
@ -704,6 +706,10 @@ static void json_add_channel(struct lightningd *ld,
|
|||
u32 feerate;
|
||||
|
||||
json_object_start(response, key);
|
||||
if (peer) {
|
||||
json_add_node_id(response, "peer_id", &peer->id);
|
||||
json_add_bool(response, "peer_connected", peer->connected == PEER_CONNECTED);
|
||||
}
|
||||
json_add_string(response, "state", channel_state_name(channel));
|
||||
if (channel->last_tx && !invalid_last_tx(channel->last_tx)) {
|
||||
struct bitcoin_txid txid;
|
||||
|
@ -1936,13 +1942,13 @@ static void json_add_peer(struct lightningd *ld,
|
|||
}
|
||||
|
||||
json_array_start(response, "channels");
|
||||
json_add_uncommitted_channel(response, p->uncommitted_channel);
|
||||
json_add_uncommitted_channel(response, p->uncommitted_channel, NULL);
|
||||
|
||||
list_for_each(&p->channels, channel, list) {
|
||||
if (channel_unsaved(channel))
|
||||
json_add_unsaved_channel(response, channel);
|
||||
json_add_unsaved_channel(response, channel, NULL);
|
||||
else
|
||||
json_add_channel(ld, response, NULL, channel);
|
||||
json_add_channel(ld, response, NULL, channel, NULL);
|
||||
}
|
||||
json_array_end(response);
|
||||
|
||||
|
|
|
@ -445,11 +445,15 @@ void json_add_u64(struct json_stream *result UNNEEDED, const char *fieldname UNN
|
|||
{ fprintf(stderr, "json_add_u64 called!\n"); abort(); }
|
||||
/* Generated stub for json_add_uncommitted_channel */
|
||||
void json_add_uncommitted_channel(struct json_stream *response UNNEEDED,
|
||||
const struct uncommitted_channel *uc UNNEEDED)
|
||||
const struct uncommitted_channel *uc UNNEEDED,
|
||||
/* Only set for listpeerchannels */
|
||||
const struct peer *peer UNNEEDED)
|
||||
{ fprintf(stderr, "json_add_uncommitted_channel called!\n"); abort(); }
|
||||
/* Generated stub for json_add_unsaved_channel */
|
||||
void json_add_unsaved_channel(struct json_stream *response UNNEEDED,
|
||||
const struct channel *channel UNNEEDED)
|
||||
const struct channel *channel UNNEEDED,
|
||||
/* Only set for listpeerchannels */
|
||||
const struct peer *peer UNNEEDED)
|
||||
{ fprintf(stderr, "json_add_unsaved_channel called!\n"); abort(); }
|
||||
/* Generated stub for json_array_end */
|
||||
void json_array_end(struct json_stream *js UNNEEDED)
|
||||
|
|
|
@ -403,11 +403,15 @@ void json_add_u64(struct json_stream *result UNNEEDED, const char *fieldname UNN
|
|||
{ fprintf(stderr, "json_add_u64 called!\n"); abort(); }
|
||||
/* Generated stub for json_add_uncommitted_channel */
|
||||
void json_add_uncommitted_channel(struct json_stream *response UNNEEDED,
|
||||
const struct uncommitted_channel *uc UNNEEDED)
|
||||
const struct uncommitted_channel *uc UNNEEDED,
|
||||
/* Only set for listpeerchannels */
|
||||
const struct peer *peer UNNEEDED)
|
||||
{ fprintf(stderr, "json_add_uncommitted_channel called!\n"); abort(); }
|
||||
/* Generated stub for json_add_unsaved_channel */
|
||||
void json_add_unsaved_channel(struct json_stream *response UNNEEDED,
|
||||
const struct channel *channel UNNEEDED)
|
||||
const struct channel *channel UNNEEDED,
|
||||
/* Only set for listpeerchannels */
|
||||
const struct peer *peer UNNEEDED)
|
||||
{ fprintf(stderr, "json_add_unsaved_channel called!\n"); abort(); }
|
||||
/* Generated stub for json_array_end */
|
||||
void json_array_end(struct json_stream *js UNNEEDED)
|
||||
|
|
Loading…
Add table
Reference in a new issue