From a333df449a63ed7971bdd7c58c439e6d5de2a3ba Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Tue, 29 Oct 2019 12:20:34 -0500 Subject: [PATCH] listpeers: show close_to address If a 'upfront_shutdown_script' was specified, show the address + scriptpubky in `listpeers` Changelog-added: JSON API: `listpeers` channels now include `close_to` and `close_to_addr` iff a `close_to` address was specified at channel open --- lightningd/peer_control.c | 12 ++++++++++++ tests/test_connection.py | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index 43fa782ab..19536b380 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -619,6 +620,17 @@ static void json_add_channel(struct lightningd *ld, json_add_string(response, "channel_id", type_to_string(tmpctx, struct channel_id, &cid)); json_add_txid(response, "funding_txid", &channel->funding_txid); + + if (channel->shutdown_scriptpubkey[LOCAL]) { + char *addr = encode_scriptpubkey_to_addr(tmpctx, + get_chainparams(ld), + channel->shutdown_scriptpubkey[LOCAL]); + if (addr) + json_add_string(response, "close_to_addr", addr); + json_add_hex_talarr(response, "close_to", + channel->shutdown_scriptpubkey[LOCAL]); + } + json_add_bool( response, "private", !(channel->channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL)); diff --git a/tests/test_connection.py b/tests/test_connection.py index 3ab6705fa..5cdaad9cc 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1133,12 +1133,16 @@ def test_funding_close_upfront(node_factory, bitcoind): # check that you can provide a closing address upfront addr = l1.rpc.newaddr()['bech32'] _fundchannel(l1, l2, addr) + # confirm that it appears in listpeers + assert addr == only_one(l1.rpc.listpeers()['peers'])['channels'][1]['close_to_addr'] resp = l1.rpc.close(l2.info['id']) assert resp['type'] == 'mutual' assert only_one(only_one(bitcoind.rpc.decoderawtransaction(resp['tx'])['vout'])['scriptPubKey']['addresses']) == addr # check that passing in the same addr to close works + addr = bitcoind.rpc.getnewaddress() _fundchannel(l1, l2, addr) + assert addr == only_one(l1.rpc.listpeers()['peers'])['channels'][2]['close_to_addr'] resp = l1.rpc.close(l2.info['id'], destination=addr) assert resp['type'] == 'mutual' assert only_one(only_one(bitcoind.rpc.decoderawtransaction(resp['tx'])['vout'])['scriptPubKey']['addresses']) == addr