newaddr: deprecate 'address' output.

It doesn't make sense with 'all', and it's ok to be explicit.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-03-04 13:43:49 +10:30
committed by Christian Decker
parent 3e67c09d5e
commit 049f2351d4
7 changed files with 28 additions and 24 deletions

View File

@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Note: You should always set `allow-deprecated-apis=false` to test for Note: You should always set `allow-deprecated-apis=false` to test for
changes. changes.
- JSON API: `newaddr` output field `address`: use `bech32` or `p2sh-segwit` instead.
### Removed ### Removed
### Fixed ### Fixed

View File

@@ -198,7 +198,7 @@ def test_closing_different_fees(node_factory, bitcoind, executor):
amounts = [0, 545999, 546000] amounts = [0, 545999, 546000]
num_peers = len(feerates) * len(amounts) num_peers = len(feerates) * len(amounts)
addr = l1.rpc.newaddr()['address'] addr = l1.rpc.newaddr()['bech32']
bitcoind.rpc.sendtoaddress(addr, 1) bitcoind.rpc.sendtoaddress(addr, 1)
numfunds = len(l1.rpc.listfunds()['outputs']) numfunds = len(l1.rpc.listfunds()['outputs'])
bitcoind.generate_block(1) bitcoind.generate_block(1)
@@ -501,7 +501,7 @@ def test_onchain_unwatch(node_factory, bitcoind):
# Now test unrelated onchain churn. # Now test unrelated onchain churn.
# Daemon gets told about wallet; says it doesn't care. # Daemon gets told about wallet; says it doesn't care.
l1.rpc.withdraw(l1.rpc.newaddr()['address'], 'all') l1.rpc.withdraw(l1.rpc.newaddr()['bech32'], 'all')
bitcoind.generate_block(1) bitcoind.generate_block(1)
l1.daemon.wait_for_log("but we don't care") l1.daemon.wait_for_log("but we don't care")
@@ -510,7 +510,7 @@ def test_onchain_unwatch(node_factory, bitcoind):
# So these should not generate further messages # So these should not generate further messages
for i in range(5): for i in range(5):
l1.rpc.withdraw(l1.rpc.newaddr()['address'], 'all') l1.rpc.withdraw(l1.rpc.newaddr()['bech32'], 'all')
bitcoind.generate_block(1) bitcoind.generate_block(1)
# Make sure it digests the block # Make sure it digests the block
sync_blockheight(bitcoind, [l1]) sync_blockheight(bitcoind, [l1])

View File

@@ -621,7 +621,7 @@ def test_funding_fail(node_factory, bitcoind):
funds = 1000000 funds = 1000000
addr = l1.rpc.newaddr()['address'] addr = l1.rpc.newaddr()['bech32']
l1.bitcoin.rpc.sendtoaddress(addr, funds / 10**8) l1.bitcoin.rpc.sendtoaddress(addr, funds / 10**8)
bitcoind.generate_block(1) bitcoind.generate_block(1)
@@ -661,7 +661,7 @@ def test_funding_toolarge(node_factory, bitcoind):
# Send funds. # Send funds.
amount = 2**24 amount = 2**24
bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['address'], amount / 10**8 + 0.01) bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'], amount / 10**8 + 0.01)
bitcoind.generate_block(1) bitcoind.generate_block(1)
# Wait for it to arrive. # Wait for it to arrive.
@@ -701,7 +701,7 @@ def test_lockin_between_restart(node_factory, bitcoind):
def test_funding_while_offline(node_factory, bitcoind): def test_funding_while_offline(node_factory, bitcoind):
l1 = node_factory.get_node() l1 = node_factory.get_node()
addr = l1.rpc.newaddr()['address'] addr = l1.rpc.newaddr()['bech32']
sync_blockheight(bitcoind, [l1]) sync_blockheight(bitcoind, [l1])
# l1 goes down. # l1 goes down.
@@ -1154,13 +1154,13 @@ def test_no_fee_estimate(node_factory, bitcoind, executor):
# Can't withdraw either. # Can't withdraw either.
with pytest.raises(RpcError, match=r'Cannot estimate fees'): with pytest.raises(RpcError, match=r'Cannot estimate fees'):
l1.rpc.withdraw(l2.rpc.newaddr()['address'], 'all') l1.rpc.withdraw(l2.rpc.newaddr()['bech32'], 'all')
# Can't use feerate names, either. # Can't use feerate names, either.
with pytest.raises(RpcError, match=r'Cannot estimate fees'): with pytest.raises(RpcError, match=r'Cannot estimate fees'):
l1.rpc.withdraw(l2.rpc.newaddr()['address'], 'all', 'urgent') l1.rpc.withdraw(l2.rpc.newaddr()['bech32'], 'all', 'urgent')
l1.rpc.withdraw(l2.rpc.newaddr()['address'], 'all', 'normal') l1.rpc.withdraw(l2.rpc.newaddr()['bech32'], 'all', 'normal')
l1.rpc.withdraw(l2.rpc.newaddr()['address'], 'all', 'slow') l1.rpc.withdraw(l2.rpc.newaddr()['bech32'], 'all', 'slow')
with pytest.raises(RpcError, match=r'Cannot estimate fees'): with pytest.raises(RpcError, match=r'Cannot estimate fees'):
l1.rpc.fundchannel(l2.info['id'], 10**6, 'urgent') l1.rpc.fundchannel(l2.info['id'], 10**6, 'urgent')
@@ -1168,7 +1168,7 @@ def test_no_fee_estimate(node_factory, bitcoind, executor):
l1.rpc.fundchannel(l2.info['id'], 10**6, 'slow') l1.rpc.fundchannel(l2.info['id'], 10**6, 'slow')
# Can with manual feerate. # Can with manual feerate.
l1.rpc.withdraw(l2.rpc.newaddr()['address'], 10000, '1500perkb') l1.rpc.withdraw(l2.rpc.newaddr()['bech32'], 10000, '1500perkb')
l1.rpc.fundchannel(l2.info['id'], 10**6, '2000perkw', minconf=0) l1.rpc.fundchannel(l2.info['id'], 10**6, '2000perkw', minconf=0)
# Make sure we clean up cahnnel for later attempt. # Make sure we clean up cahnnel for later attempt.
@@ -1210,7 +1210,7 @@ def test_no_fee_estimate(node_factory, bitcoind, executor):
l1.rpc.fundchannel(l2.info['id'], 10**6, 'slow') l1.rpc.fundchannel(l2.info['id'], 10**6, 'slow')
# Can withdraw (use urgent feerate). # Can withdraw (use urgent feerate).
l1.rpc.withdraw(l2.rpc.newaddr()['address'], 'all', 'urgent') l1.rpc.withdraw(l2.rpc.newaddr()['bech32'], 'all', 'urgent')
@unittest.skipIf(not DEVELOPER, "needs --dev-disconnect") @unittest.skipIf(not DEVELOPER, "needs --dev-disconnect")

View File

@@ -11,8 +11,8 @@ import unittest
def test_invoice(node_factory): def test_invoice(node_factory):
l1, l2 = node_factory.line_graph(2, fundchannel=False) l1, l2 = node_factory.line_graph(2, fundchannel=False)
addr1 = l2.rpc.newaddr('bech32')['address'] addr1 = l2.rpc.newaddr('bech32')['bech32']
addr2 = l2.rpc.newaddr('p2sh-segwit')['address'] addr2 = l2.rpc.newaddr('p2sh-segwit')['p2sh-segwit']
before = int(time.time()) before = int(time.time())
inv = l1.rpc.invoice(123000, 'label', 'description', '3700', [addr1, addr2]) inv = l1.rpc.invoice(123000, 'label', 'description', '3700', [addr1, addr2])
after = int(time.time()) after = int(time.time())

View File

@@ -365,7 +365,7 @@ def test_withdraw(node_factory, bitcoind):
# Don't get any funds from previous runs. # Don't get any funds from previous runs.
l1 = node_factory.get_node(random_hsm=True) l1 = node_factory.get_node(random_hsm=True)
l2 = node_factory.get_node(random_hsm=True) l2 = node_factory.get_node(random_hsm=True)
addr = l1.rpc.newaddr()['address'] addr = l1.rpc.newaddr()['bech32']
# Add some funds to withdraw later # Add some funds to withdraw later
for i in range(10): for i in range(10):
@@ -401,7 +401,7 @@ def test_withdraw(node_factory, bitcoind):
# Now send some money to l2. # Now send some money to l2.
# lightningd uses P2SH-P2WPKH # lightningd uses P2SH-P2WPKH
waddr = l2.rpc.newaddr('bech32')['address'] waddr = l2.rpc.newaddr('bech32')['bech32']
l1.rpc.withdraw(waddr, 2 * amount) l1.rpc.withdraw(waddr, 2 * amount)
bitcoind.generate_block(1) bitcoind.generate_block(1)
@@ -471,7 +471,7 @@ def test_withdraw(node_factory, bitcoind):
assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=0')[0]['c'] == 6 assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=0')[0]['c'] == 6
# Test withdrawal to self. # Test withdrawal to self.
l1.rpc.withdraw(l1.rpc.newaddr('bech32')['address'], 'all', minconf=0) l1.rpc.withdraw(l1.rpc.newaddr('bech32')['bech32'], 'all', minconf=0)
bitcoind.generate_block(1) bitcoind.generate_block(1)
assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=0')[0]['c'] == 1 assert l1.db_query('SELECT COUNT(*) as c FROM outputs WHERE status=0')[0]['c'] == 1
@@ -489,7 +489,7 @@ def test_addfunds_from_block(node_factory, bitcoind):
# Previous runs with same bitcoind can leave funds! # Previous runs with same bitcoind can leave funds!
l1 = node_factory.get_node(random_hsm=True) l1 = node_factory.get_node(random_hsm=True)
addr = l1.rpc.newaddr()['address'] addr = l1.rpc.newaddr()['bech32']
bitcoind.rpc.sendtoaddress(addr, 0.1) bitcoind.rpc.sendtoaddress(addr, 0.1)
bitcoind.generate_block(1) bitcoind.generate_block(1)
@@ -503,7 +503,7 @@ def test_addfunds_from_block(node_factory, bitcoind):
assert output['address'] == addr assert output['address'] == addr
# Send all our money to a P2WPKH address this time. # Send all our money to a P2WPKH address this time.
addr = l1.rpc.newaddr("bech32")['address'] addr = l1.rpc.newaddr("bech32")['bech32']
l1.rpc.withdraw(addr, "all") l1.rpc.withdraw(addr, "all")
bitcoind.generate_block(1) bitcoind.generate_block(1)
time.sleep(1) time.sleep(1)
@@ -804,7 +804,7 @@ def test_blockchaintrack(node_factory, bitcoind):
"""Check that we track the blockchain correctly across reorgs """Check that we track the blockchain correctly across reorgs
""" """
l1 = node_factory.get_node(random_hsm=True) l1 = node_factory.get_node(random_hsm=True)
addr = l1.rpc.newaddr()['address'] addr = l1.rpc.newaddr()['bech32']
###################################################################### ######################################################################
# First failure scenario: rollback on startup doesn't work, # First failure scenario: rollback on startup doesn't work,

View File

@@ -438,7 +438,7 @@ class LightningNode(object):
return {'address': addr, 'wallettxid': wallettxid, 'fundingtx': fundingtx} return {'address': addr, 'wallettxid': wallettxid, 'fundingtx': fundingtx}
def fundwallet(self, sats, addrtype="p2sh-segwit"): def fundwallet(self, sats, addrtype="p2sh-segwit"):
addr = self.rpc.newaddr(addrtype)['address'] addr = self.rpc.newaddr(addrtype)[addrtype]
txid = self.bitcoin.rpc.sendtoaddress(addr, sats / 10**8) txid = self.bitcoin.rpc.sendtoaddress(addr, sats / 10**8)
self.bitcoin.generate_block(1) self.bitcoin.generate_block(1)
self.daemon.wait_for_log('Owning output .* txid {}'.format(txid)) self.daemon.wait_for_log('Owning output .* txid {}'.format(txid))
@@ -529,7 +529,7 @@ class LightningNode(object):
def fund_channel(self, l2, amount, wait_for_active=True): def fund_channel(self, l2, amount, wait_for_active=True):
# Give yourself some funds to work with # Give yourself some funds to work with
addr = self.rpc.newaddr()['address'] addr = self.rpc.newaddr()['bech32']
self.bitcoin.rpc.sendtoaddress(addr, (amount + 1000000) / 10**8) self.bitcoin.rpc.sendtoaddress(addr, (amount + 1000000) / 10**8)
numfunds = len(self.rpc.listfunds()['outputs']) numfunds = len(self.rpc.listfunds()['outputs'])
self.bitcoin.generate_block(1) self.bitcoin.generate_block(1)
@@ -847,7 +847,7 @@ class NodeFactory(object):
# If we got here, we want to fund channels # If we got here, we want to fund channels
for src, dst in connections: for src, dst in connections:
addr = src.rpc.newaddr()['address'] addr = src.rpc.newaddr()['bech32']
src.bitcoin.rpc.sendtoaddress(addr, (fundamount + 1000000) / 10**8) src.bitcoin.rpc.sendtoaddress(addr, (fundamount + 1000000) / 10**8)
bitcoin.generate_block(1) bitcoin.generate_block(1)

View File

@@ -21,6 +21,7 @@
#include <lightningd/jsonrpc.h> #include <lightningd/jsonrpc.h>
#include <lightningd/lightningd.h> #include <lightningd/lightningd.h>
#include <lightningd/log.h> #include <lightningd/log.h>
#include <lightningd/options.h>
#include <lightningd/peer_control.h> #include <lightningd/peer_control.h>
#include <lightningd/subd.h> #include <lightningd/subd.h>
#include <wally_bip32.h> #include <wally_bip32.h>
@@ -336,6 +337,7 @@ static struct command_result *json_newaddr(struct command *cmd,
response = json_stream_success(cmd); response = json_stream_success(cmd);
json_object_start(response, NULL); json_object_start(response, NULL);
if (deprecated_apis)
json_add_string(response, "address", bech32 ? bech32 : p2sh); json_add_string(response, "address", bech32 ? bech32 : p2sh);
if (*addrtype & ADDR_BECH32) if (*addrtype & ADDR_BECH32)
json_add_string(response, "bech32", bech32); json_add_string(response, "bech32", bech32);