Skip to content

Commit

Permalink
listpeers: show close_to address
Browse files Browse the repository at this point in the history
If a 'upfront_shutdown_script' was specified, show the address +
scriptpubky in `listpeers`
  • Loading branch information
niftynei committed Oct 29, 2019
1 parent d0297ee commit 9325204
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- JSON API: `listpeers` channels now include `close_to` and `close_to_addr` iff a `close_to` address
was specified at channel open

### Changed

### Deprecated

Note: You should always set `allow-deprecated-apis=false` to test for
changes.

### Removed

### Fixed


## [0.7.3] - 2019-10-18: "Bitcoin's Proof of Stake"

This release named by @trueptolemy.
Expand Down
11 changes: 11 additions & 0 deletions lightningd/peer_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <ccan/take/take.h>
#include <ccan/tal/str/str.h>
#include <channeld/gen_channel_wire.h>
#include <common/addr.h>
#include <common/dev_disconnect.h>
#include <common/features.h>
#include <common/htlc_trim.h>
Expand Down Expand Up @@ -619,6 +620,16 @@ 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]) {
json_add_string(response, "close_to_addr",
encode_scriptpubkey_to_addr(tmpctx,
get_chainparams(ld),
channel->shutdown_scriptpubkey[LOCAL]));
json_add_hex_talarr(response, "close_to",
channel->shutdown_scriptpubkey[LOCAL]);
}

json_add_bool(
response, "private",
!(channel->channel_flags & CHANNEL_FLAGS_ANNOUNCE_CHANNEL));
Expand Down
4 changes: 4 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,12 +1133,16 @@ def _fundchannel(l1, l2, close_to):
# 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
Expand Down

0 comments on commit 9325204

Please sign in to comment.