diff --git a/lightningd/dual_open_control.c b/lightningd/dual_open_control.c index 5a5bfab2c..41de4264b 100644 --- a/lightningd/dual_open_control.c +++ b/lightningd/dual_open_control.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -73,6 +74,52 @@ void kill_unsaved_channel(struct channel *channel, tal_free(channel); } +void json_add_unsaved_channel(struct json_stream *response, + const struct channel *channel) +{ + struct amount_msat total; + + if (!channel) + return; + + /* If we're chatting but no channel, that's shown by connected: True */ + if (!channel->open_attempt) + return; + + json_object_start(response, NULL); + 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 ? + "local" : "remote"); + json_array_start(response, "status"); + for (size_t i = 0; i < ARRAY_SIZE(channel->billboard.permanent); i++) { + if (!channel->billboard.permanent[i]) + continue; + json_add_string(response, NULL, + channel->billboard.permanent[i]); + } + if (channel->billboard.transient) + json_add_string(response, NULL, channel->billboard.transient); + json_array_end(response); + + /* These should never fail. */ + if (amount_sat_to_msat(&total, channel->open_attempt->funding)) { + json_add_amount_msat_compat(response, total, + "msatoshi_to_us", "to_us_msat"); + /* This will change if peer adds funds */ + json_add_amount_msat_compat(response, total, + "msatoshi_total", "total_msat"); + } + + json_array_start(response, "features"); + /* v2 channels assumed to have both static_remotekey + anchor_outputs */ + json_add_string(response, NULL, "option_static_remotekey"); + json_add_string(response, NULL, "option_anchor_outputs"); + json_array_end(response); + json_object_end(response); +} + + static struct channel_inflight * channel_current_inflight(struct channel *channel) { diff --git a/lightningd/dual_open_control.h b/lightningd/dual_open_control.h index a28092b84..53feb41bb 100644 --- a/lightningd/dual_open_control.h +++ b/lightningd/dual_open_control.h @@ -21,4 +21,7 @@ void dualopen_tell_depth(struct subd *dualopend, u32 depth); void kill_unsaved_channel(struct channel *channel, const char *why); + +void json_add_unsaved_channel(struct json_stream *response, + const struct channel *channel); #endif /* LIGHTNING_LIGHTNINGD_DUAL_OPEN_CONTROL_H */ diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 4b6fed0e0..9d1a04e8f 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1387,8 +1387,14 @@ static void json_add_peer(struct lightningd *ld, json_array_start(response, "channels"); json_add_uncommitted_channel(response, p->uncommitted_channel); - list_for_each(&p->channels, channel, list) - json_add_channel(ld, response, NULL, channel); + list_for_each(&p->channels, channel, list) { +#if EXPERIMENTAL_FEATURES + if (channel_unsaved(channel)) + json_add_unsaved_channel(response, channel); + else +#endif /* EXPERIMENTAL_FEATURES */ + json_add_channel(ld, response, NULL, channel); + } json_array_end(response); if (ll) diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 115d8d212..094c5d0e1 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -320,6 +320,10 @@ void json_add_txid(struct json_stream *result UNNEEDED, const char *fieldname UN void json_add_uncommitted_channel(struct json_stream *response UNNEEDED, const struct uncommitted_channel *uc 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) +{ fprintf(stderr, "json_add_unsaved_channel called!\n"); abort(); } /* Generated stub for json_array_end */ void json_array_end(struct json_stream *js UNNEEDED) { fprintf(stderr, "json_array_end called!\n"); abort(); } diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index 0d685fc49..3e7a90382 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -1834,4 +1834,4 @@ struct db_query db_postgres_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:05cb7231674d7f4be2ca9629d185aa9f77fcbb92ffa09ec62eefbb9a4d13b414 +// SHA256STAMP:d0a5c4dda6f04a6c1b80f3226723eedd6eefef3327f6bf047546f43d3ea8ab8f diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index 9f235294d..cf52163fc 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -1834,4 +1834,4 @@ struct db_query db_sqlite3_queries[] = { #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:05cb7231674d7f4be2ca9629d185aa9f77fcbb92ffa09ec62eefbb9a4d13b414 +// SHA256STAMP:d0a5c4dda6f04a6c1b80f3226723eedd6eefef3327f6bf047546f43d3ea8ab8f diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index 9211b89b8..0d603db33 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -1202,11 +1202,11 @@ msgstr "" msgid "not a valid SQL statement" msgstr "" -#: wallet/test/run-wallet.c:1414 +#: wallet/test/run-wallet.c:1418 msgid "SELECT COUNT(1) FROM channel_funding_inflights WHERE channel_id = ?;" msgstr "" -#: wallet/test/run-wallet.c:1612 +#: wallet/test/run-wallet.c:1616 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:bf5f416a1538ee73dfdedcab076dd11be8f65f5afda71a02557544fa376a391b +# SHA256STAMP:5e6810f5b92f800a08b2e64611534d169881c270a809d96a0babf79fee9723f9 diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index f1d2545ae..bc16e1f10 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -356,6 +356,10 @@ void json_add_u64(struct json_stream *result UNNEEDED, const char *fieldname UNN void json_add_uncommitted_channel(struct json_stream *response UNNEEDED, const struct uncommitted_channel *uc 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) +{ fprintf(stderr, "json_add_unsaved_channel called!\n"); abort(); } /* Generated stub for json_array_end */ void json_array_end(struct json_stream *js UNNEEDED) { fprintf(stderr, "json_array_end called!\n"); abort(); }