Skip to content

Commit 6d0e532

Browse files
committed
Merge #17585: rpc: deprecate getaddressinfo label
d3bc184 doc: update release notes with getaddressinfo label deprecation (Jon Atack) 72af93f test: getaddressinfo label deprecation test (Jon Atack) d48875f rpc: deprecate getaddressinfo label field (Jon Atack) dc0cabe test: remove getaddressinfo label tests (Jon Atack) c7654af doc: address pr17578 review feedback (Jon Atack) Pull request description: This PR builds on #17578 (now merged) and deprecates the rpc getaddressinfo `label` field. The deprecated behavior can be re-enabled by starting bitcoind with `-deprecatedrpc=label`. See http://www.erisian.com.au/bitcoin-core-dev/log-2019-11-22.html#l-622 and bitcoin/bitcoin#17283 (comment) for more context. Reviewers: This PR may be tested manually by building, then running bitcoind with and without the `-deprecatedrpc=label` flag while verifying the rpc getaddressinfo output and help text. Next step: add support for multiple labels. ACKs for top commit: jnewbery: ACK d3bc184 laanwj: ACK d3bc184 meshcollider: utACK d3bc184 Tree-SHA512: f954402884ec54977def332c8160fd892f289b0d2aee1e91fed9ac3220f7e5b1f7fc6421b84cc7a5c824a0582eca4e6fc194e4e33ddd378c733c8941ac45f56d
2 parents f05c1ac + d3bc184 commit 6d0e532

10 files changed

+75
-33
lines changed

doc/release-notes-17578.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
Deprecated or removed RPCs
22
--------------------------
33

4-
- The `getaddressinfo` RPC `labels` field now returns an array of label name
5-
strings. Previously, it returned an array of JSON objects containing `name` and
6-
`purpose` key/value pairs, which is now deprecated and will be removed in
7-
0.21. To re-enable the previous behavior, launch bitcoind with
8-
`-deprecatedrpc=labelspurpose`.
4+
- RPC `getaddressinfo` changes:
5+
6+
- the `label` field has been deprecated in favor of the `labels` field and
7+
will be removed in 0.21. It can be re-enabled in the interim by launching
8+
with `-deprecatedrpc=label`.
9+
10+
- the `labels` behavior of returning an array of JSON objects containing name
11+
and purpose key/value pairs has been deprecated in favor of an array of
12+
label names and will be removed in 0.21. The previous behavior can be
13+
re-enabled in the interim by launching with `-deprecatedrpc=labelspurpose`.

src/wallet/rpcwallet.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3766,18 +3766,18 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
37663766
" getaddressinfo output fields for the embedded address, excluding metadata (timestamp, hdkeypath,\n"
37673767
" hdseedid) and relation to the wallet (ismine, iswatchonly).\n"
37683768
" \"iscompressed\" : true|false, (boolean, optional) If the pubkey is compressed.\n"
3769-
" \"label\" : \"label\" (string) The label associated with the address. Defaults to \"\". Equivalent to the label name in the labels array below.\n"
3769+
" \"label\" : \"label\" (string) DEPRECATED. The label associated with the address. Defaults to \"\". Replaced by the labels array below.\n"
37703770
" \"timestamp\" : timestamp, (number, optional) The creation time of the key, if available, expressed in " + UNIX_EPOCH_TIME + ".\n"
37713771
" \"hdkeypath\" : \"keypath\" (string, optional) The HD keypath, if the key is HD and available.\n"
37723772
" \"hdseedid\" : \"<hash160>\" (string, optional) The Hash160 of the HD seed.\n"
37733773
" \"hdmasterfingerprint\" : \"<hash160>\" (string, optional) The fingerprint of the master key.\n"
3774-
" \"labels\" (json object) An array of labels associated with the address. Currently limited to one label but returned\n"
3775-
" as an array to keep the API stable if multiple labels are enabled in the future.\n"
3774+
" \"labels\" (array) Array of labels associated with the address. Currently limited to one label but returned\n"
3775+
" as an array to keep the API stable if multiple labels are enabled in the future.\n"
37763776
" [\n"
3777-
" \"label name\" (string) The label name. Defaults to \"\". Equivalent to the label field above.\n\n"
3777+
" \"label name\" (string) The label name. Defaults to \"\".\n"
37783778
" DEPRECATED, will be removed in 0.21. To re-enable, launch bitcoind with `-deprecatedrpc=labelspurpose`:\n"
3779-
" { (json object of label data)\n"
3780-
" \"name\" : \"label name\" (string) The label name. Defaults to \"\". Equivalent to the label field above.\n"
3779+
" {\n"
3780+
" \"name\" : \"label name\" (string) The label name. Defaults to \"\".\n"
37813781
" \"purpose\" : \"purpose\" (string) The purpose of the associated address (send or receive).\n"
37823782
" }\n"
37833783
" ]\n"
@@ -3821,10 +3821,10 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
38213821
UniValue detail = DescribeWalletAddress(pwallet, dest);
38223822
ret.pushKVs(detail);
38233823

3824-
// Return label field if existing. Currently only one label can be
3825-
// associated with an address, so the label should be equivalent to the
3824+
// DEPRECATED: Return label field if existing. Currently only one label can
3825+
// be associated with an address, so the label should be equivalent to the
38263826
// value of the name key/value pair in the labels array below.
3827-
if (pwallet->mapAddressBook.count(dest)) {
3827+
if ((pwallet->chain().rpcEnableDeprecated("label")) && (pwallet->mapAddressBook.count(dest))) {
38283828
ret.pushKV("label", pwallet->mapAddressBook[dest].name);
38293829
}
38303830

@@ -3847,12 +3847,11 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
38473847
// associated with an address, but we return an array so the API remains
38483848
// stable if we allow multiple labels to be associated with an address in
38493849
// the future.
3850-
//
3851-
// DEPRECATED: The previous behavior of returning an array containing a JSON
3852-
// object of `name` and `purpose` key/value pairs has been deprecated.
38533850
UniValue labels(UniValue::VARR);
38543851
std::map<CTxDestination, CAddressBookData>::iterator mi = pwallet->mapAddressBook.find(dest);
38553852
if (mi != pwallet->mapAddressBook.end()) {
3853+
// DEPRECATED: The previous behavior of returning an array containing a
3854+
// JSON object of `name` and `purpose` key/value pairs is deprecated.
38563855
if (pwallet->chain().rpcEnableDeprecated("labelspurpose")) {
38573856
labels.push_back(AddressBookDataToJSON(mi->second, true));
38583857
} else {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2020 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""
6+
Test deprecation of the RPC getaddressinfo `label` field. It has been
7+
superceded by the `labels` field.
8+
9+
"""
10+
from test_framework.test_framework import BitcoinTestFramework
11+
12+
class GetAddressInfoLabelDeprecationTest(BitcoinTestFramework):
13+
def set_test_params(self):
14+
self.num_nodes = 2
15+
self.setup_clean_chain = False
16+
# Start node[0] with -deprecatedrpc=label, and node[1] without.
17+
self.extra_args = [["-deprecatedrpc=label"], []]
18+
19+
def skip_test_if_missing_module(self):
20+
self.skip_if_no_wallet()
21+
22+
def test_label_with_deprecatedrpc_flag(self):
23+
self.log.info("Test getaddressinfo label with -deprecatedrpc flag")
24+
node = self.nodes[0]
25+
address = node.getnewaddress()
26+
info = node.getaddressinfo(address)
27+
assert "label" in info
28+
29+
def test_label_without_deprecatedrpc_flag(self):
30+
self.log.info("Test getaddressinfo label without -deprecatedrpc flag")
31+
node = self.nodes[1]
32+
address = node.getnewaddress()
33+
info = node.getaddressinfo(address)
34+
assert "label" not in info
35+
36+
def run_test(self):
37+
"""Test getaddressinfo label with and without -deprecatedrpc flag."""
38+
self.test_label_with_deprecatedrpc_flag()
39+
self.test_label_without_deprecatedrpc_flag()
40+
41+
42+
if __name__ == '__main__':
43+
GetAddressInfoLabelDeprecationTest().main()

test/functional/rpc_getaddressinfo_labels_purpose_deprecation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""
66
Test deprecation of RPC getaddressinfo `labels` returning an array
7-
containing a JSON hash of `name` and purpose` key-value pairs. It now
8-
returns an array of label names.
7+
containing a JSON object of `name` and purpose` key-value pairs. It now
8+
returns an array containing only the label name.
99
1010
"""
1111
from test_framework.test_framework import BitcoinTestFramework

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
'feature_blocksdir.py',
214214
'feature_config_args.py',
215215
'rpc_getaddressinfo_labels_purpose_deprecation.py',
216+
'rpc_getaddressinfo_label_deprecation.py',
216217
'rpc_help.py',
217218
'feature_help.py',
218219
'feature_shutdown.py',

test/functional/wallet_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def run_test(self):
392392
for label in [u'рыба', u'𝅘𝅥𝅯']:
393393
addr = self.nodes[0].getnewaddress()
394394
self.nodes[0].setlabel(addr, label)
395-
test_address(self.nodes[0], addr, label=label, labels=[label])
395+
test_address(self.nodes[0], addr, labels=[label])
396396
assert label in self.nodes[0].listlabels()
397397
self.nodes[0].rpc.ensure_ascii = True # restore to default
398398

test/functional/wallet_import_with_label.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def run_test(self):
3636
address,
3737
iswatchonly=True,
3838
ismine=False,
39-
label=label,
4039
labels=[label])
4140

4241
self.log.info(
@@ -45,7 +44,7 @@ def run_test(self):
4544
)
4645
priv_key = self.nodes[0].dumpprivkey(address)
4746
self.nodes[1].importprivkey(priv_key)
48-
test_address(self.nodes[1], address, label=label, labels=[label])
47+
test_address(self.nodes[1], address, labels=[label])
4948

5049
self.log.info(
5150
"Test importaddress without label and importprivkey with label."
@@ -57,7 +56,6 @@ def run_test(self):
5756
address2,
5857
iswatchonly=True,
5958
ismine=False,
60-
label="",
6159
labels=[""])
6260

6361
self.log.info(
@@ -68,7 +66,7 @@ def run_test(self):
6866
label2 = "Test Label 2"
6967
self.nodes[1].importprivkey(priv_key2, label2)
7068

71-
test_address(self.nodes[1], address2, label=label2, labels=[label2])
69+
test_address(self.nodes[1], address2, labels=[label2])
7270

7371
self.log.info("Test importaddress with label and importprivkey with label.")
7472
self.log.info("Import a watch-only address with a label.")
@@ -79,7 +77,6 @@ def run_test(self):
7977
address3,
8078
iswatchonly=True,
8179
ismine=False,
82-
label=label3_addr,
8380
labels=[label3_addr])
8481

8582
self.log.info(
@@ -90,7 +87,7 @@ def run_test(self):
9087
label3_priv = "Test Label 3 for importprivkey"
9188
self.nodes[1].importprivkey(priv_key3, label3_priv)
9289

93-
test_address(self.nodes[1], address3, label=label3_priv, labels=[label3_priv])
90+
test_address(self.nodes[1], address3, labels=[label3_priv])
9491

9592
self.log.info(
9693
"Test importprivkey won't label new dests with the same "
@@ -104,7 +101,6 @@ def run_test(self):
104101
address4,
105102
iswatchonly=True,
106103
ismine=False,
107-
label=label4_addr,
108104
labels=[label4_addr],
109105
embedded=None)
110106

@@ -118,9 +114,9 @@ def run_test(self):
118114
self.nodes[1].importprivkey(priv_key4)
119115
embedded_addr = self.nodes[1].getaddressinfo(address4)['embedded']['address']
120116

121-
test_address(self.nodes[1], embedded_addr, label="", labels=[""])
117+
test_address(self.nodes[1], embedded_addr, labels=[""])
122118

123-
test_address(self.nodes[1], address4, label=label4_addr, labels=[label4_addr])
119+
test_address(self.nodes[1], address4, labels=[label4_addr])
124120

125121
self.stop_nodes()
126122

test/functional/wallet_importmulti.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,6 @@ def run_test(self):
569569
key.p2sh_p2wpkh_addr,
570570
solvable=True,
571571
ismine=True,
572-
label=p2sh_p2wpkh_label,
573572
labels=[p2sh_p2wpkh_label])
574573

575574
# Test ranged descriptor fails if range is not specified
@@ -641,7 +640,6 @@ def run_test(self):
641640
key.p2pkh_addr,
642641
solvable=True,
643642
ismine=False,
644-
label=p2pkh_label,
645643
labels=[p2pkh_label])
646644

647645
# Test import fails if both desc and scriptPubKey are provided

test/functional/wallet_labels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def verify(self, node):
155155
if self.receive_address is not None:
156156
assert self.receive_address in self.addresses
157157
for address in self.addresses:
158-
test_address(node, address, label=self.name, labels=[self.name])
158+
test_address(node, address, labels=[self.name])
159159
assert self.name in node.listlabels()
160160
assert_equal(
161161
node.getaddressesbylabel(self.name),

test/functional/wallet_listreceivedby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def run_test(self):
128128
# set pre-state
129129
label = ''
130130
address = self.nodes[1].getnewaddress()
131-
test_address(self.nodes[1], address, label=label, labels=[label])
131+
test_address(self.nodes[1], address, labels=[label])
132132
received_by_label_json = [r for r in self.nodes[1].listreceivedbylabel() if r["label"] == label][0]
133133
balance_by_label = self.nodes[1].getreceivedbylabel(label)
134134

0 commit comments

Comments
 (0)