Skip to content

Commit 3576ab1

Browse files
committed
[wallet] [rpc] Deprecate account RPC methods
All account RPC methods are now deprecated and can only be called if bitcoind has been started with the -deprecatedrpc=accounts switch. Affected RPC methods are: - getaccount - getaccountaddress - getaddressesbyaccount - getreceivedbyaccount - listaccouts - listreceivedbyaccount - move - setaccount
1 parent 3db1ba0 commit 3576ab1

File tree

2 files changed

+140
-2
lines changed

2 files changed

+140
-2
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ UniValue getlabeladdress(const JSONRPCRequest& request)
206206
return NullUniValue;
207207
}
208208

209+
if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "getaccountaddress") {
210+
if (request.fHelp) {
211+
throw std::runtime_error("getaccountaddress (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
212+
}
213+
throw JSONRPCError(RPC_METHOD_DEPRECATED, "getaccountaddress is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
214+
}
215+
209216
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
210217
throw std::runtime_error(
211218
"getlabeladdress \"label\" ( force ) \n"
@@ -306,6 +313,13 @@ UniValue setlabel(const JSONRPCRequest& request)
306313
return NullUniValue;
307314
}
308315

316+
if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "setaccount") {
317+
if (request.fHelp) {
318+
throw std::runtime_error("setaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
319+
}
320+
throw JSONRPCError(RPC_METHOD_DEPRECATED, "setaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
321+
}
322+
309323
if (request.fHelp || request.params.size() != 2)
310324
throw std::runtime_error(
311325
"setlabel \"address\" \"label\"\n"
@@ -353,6 +367,13 @@ UniValue getaccount(const JSONRPCRequest& request)
353367
return NullUniValue;
354368
}
355369

370+
if (!IsDeprecatedRPCEnabled("accounts")) {
371+
if (request.fHelp) {
372+
throw std::runtime_error("getaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
373+
}
374+
throw JSONRPCError(RPC_METHOD_DEPRECATED, "getaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
375+
}
376+
356377
if (request.fHelp || request.params.size() != 1)
357378
throw std::runtime_error(
358379
"getaccount \"address\"\n"
@@ -389,6 +410,13 @@ UniValue getaddressesbyaccount(const JSONRPCRequest& request)
389410
return NullUniValue;
390411
}
391412

413+
if (!IsDeprecatedRPCEnabled("accounts")) {
414+
if (request.fHelp) {
415+
throw std::runtime_error("getaddressbyaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
416+
}
417+
throw JSONRPCError(RPC_METHOD_DEPRECATED, "getaddressesbyaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
418+
}
419+
392420
if (request.fHelp || request.params.size() != 1)
393421
throw std::runtime_error(
394422
"getaddressesbyaccount \"account\"\n"
@@ -744,6 +772,13 @@ UniValue getreceivedbylabel(const JSONRPCRequest& request)
744772
return NullUniValue;
745773
}
746774

775+
if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "getreceivedbyaccount") {
776+
if (request.fHelp) {
777+
throw std::runtime_error("getreceivedbyaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
778+
}
779+
throw JSONRPCError(RPC_METHOD_DEPRECATED, "getreceivedbyaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
780+
}
781+
747782
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
748783
throw std::runtime_error(
749784
"getreceivedbylabel \"label\" ( minconf )\n"
@@ -913,6 +948,13 @@ UniValue movecmd(const JSONRPCRequest& request)
913948
return NullUniValue;
914949
}
915950

951+
if (!IsDeprecatedRPCEnabled("accounts")) {
952+
if (request.fHelp) {
953+
throw std::runtime_error("move (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
954+
}
955+
throw JSONRPCError(RPC_METHOD_DEPRECATED, "move is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
956+
}
957+
916958
if (request.fHelp || request.params.size() < 3 || request.params.size() > 5)
917959
throw std::runtime_error(
918960
"move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n"
@@ -1609,6 +1651,13 @@ UniValue listreceivedbylabel(const JSONRPCRequest& request)
16091651
return NullUniValue;
16101652
}
16111653

1654+
if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "listreceivedbyaccount") {
1655+
if (request.fHelp) {
1656+
throw std::runtime_error("listreceivedbyaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
1657+
}
1658+
throw JSONRPCError(RPC_METHOD_DEPRECATED, "listreceivedbyaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
1659+
}
1660+
16121661
if (request.fHelp || request.params.size() > 3)
16131662
throw std::runtime_error(
16141663
"listreceivedbylabel ( minconf include_empty include_watchonly)\n"
@@ -1908,6 +1957,13 @@ UniValue listaccounts(const JSONRPCRequest& request)
19081957
return NullUniValue;
19091958
}
19101959

1960+
if (!IsDeprecatedRPCEnabled("accounts")) {
1961+
if (request.fHelp) {
1962+
throw std::runtime_error("listaccounts (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
1963+
}
1964+
throw JSONRPCError(RPC_METHOD_DEPRECATED, "listaccounts is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
1965+
}
1966+
19111967
if (request.fHelp || request.params.size() > 2)
19121968
throw std::runtime_error(
19131969
"listaccounts ( minconf include_watchonly)\n"

test/functional/rpc_deprecated.py

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test deprecation of RPC calls."""
66
from test_framework.test_framework import BitcoinTestFramework
7+
from test_framework.util import assert_raises_rpc_error
78

89
class DeprecatedRpcTest(BitcoinTestFramework):
910
def set_test_params(self):
1011
self.num_nodes = 2
1112
self.setup_clean_chain = True
12-
self.extra_args = [[], ["-deprecatedrpc=validateaddress"]]
13+
self.extra_args = [[], ["-deprecatedrpc=validateaddress", "-deprecatedrpc=accounts"]]
1314

1415
def run_test(self):
1516
# This test should be used to verify correct behaviour of deprecated
@@ -20,11 +21,92 @@ def run_test(self):
2021
# self.nodes[1].createmultisig(1, [self.nodes[1].getnewaddress()])
2122

2223
self.log.info("Test validateaddress deprecation")
23-
SOME_ADDRESS = "mnvGjUy3NMj67yJ6gkK5o9e5RS33Z2Vqcu" # This is just some random address to pass as a parameter to validateaddress
24+
SOME_ADDRESS = "mnvGjUy3NMj67yJ6gkK5o9e5RS33Z2Vqcu" # This is just some random address to pass as a parameter to validateaddress
2425
dep_validate_address = self.nodes[0].validateaddress(SOME_ADDRESS)
2526
assert "ismine" not in dep_validate_address
2627
not_dep_val = self.nodes[1].validateaddress(SOME_ADDRESS)
2728
assert "ismine" in not_dep_val
2829

30+
self.log.info("Test accounts deprecation")
31+
# The following account RPC methods are deprecated:
32+
# - getaccount
33+
# - getaccountaddress
34+
# - getaddressesbyaccount
35+
# - getreceivedbyaccount
36+
# - listaccouts
37+
# - listreceivedbyaccount
38+
# - move
39+
# - setaccount
40+
#
41+
# The following 'label' RPC methods are usable both with and without the
42+
# -deprecatedrpc=accounts switch enabled.
43+
# - getlabeladdress
44+
# - getaddressesbylabel
45+
# - getreceivedbylabel
46+
# - listlabels
47+
# - listreceivedbylabel
48+
# - setlabel
49+
#
50+
address0 = self.nodes[0].getnewaddress()
51+
self.nodes[0].generatetoaddress(101, address0)
52+
address1 = self.nodes[1].getnewaddress()
53+
self.nodes[1].generatetoaddress(101, address1)
54+
55+
self.log.info("- getaccount")
56+
assert_raises_rpc_error(-32, "getaccount is deprecated", self.nodes[0].getaccount, address0)
57+
self.nodes[1].getaccount(address1)
58+
59+
self.log.info("- setaccount")
60+
assert_raises_rpc_error(-32, "setaccount is deprecated", self.nodes[0].setaccount, address0, "label0")
61+
self.nodes[1].setaccount(address1, "label1")
62+
63+
self.log.info("- setlabel")
64+
self.nodes[0].setlabel(address0, "label0")
65+
self.nodes[1].setlabel(address1, "label1")
66+
67+
self.log.info("- getaccountaddress")
68+
assert_raises_rpc_error(-32, "getaccountaddress is deprecated", self.nodes[0].getaccountaddress, "label0")
69+
self.nodes[1].getaccountaddress("label1")
70+
71+
self.log.info("- getlabeladdress")
72+
self.nodes[0].getlabeladdress("label0")
73+
self.nodes[1].getlabeladdress("label1")
74+
75+
self.log.info("- getaddressesbyaccount")
76+
assert_raises_rpc_error(-32, "getaddressesbyaccount is deprecated", self.nodes[0].getaddressesbyaccount, "label0")
77+
self.nodes[1].getaddressesbyaccount("label1")
78+
79+
self.log.info("- getaddressesbylabel")
80+
self.nodes[0].getaddressesbylabel("label0")
81+
self.nodes[1].getaddressesbylabel("label1")
82+
83+
self.log.info("- getreceivedbyaccount")
84+
assert_raises_rpc_error(-32, "getreceivedbyaccount is deprecated", self.nodes[0].getreceivedbyaccount, "label0")
85+
self.nodes[1].getreceivedbyaccount("label1")
86+
87+
self.log.info("- getreceivedbylabel")
88+
self.nodes[0].getreceivedbylabel("label0")
89+
self.nodes[1].getreceivedbylabel("label1")
90+
91+
self.log.info("- listaccounts")
92+
assert_raises_rpc_error(-32, "listaccounts is deprecated", self.nodes[0].listaccounts)
93+
self.nodes[1].listaccounts()
94+
95+
self.log.info("- listlabels")
96+
self.nodes[0].listlabels()
97+
self.nodes[1].listlabels()
98+
99+
self.log.info("- listreceivedbyaccount")
100+
assert_raises_rpc_error(-32, "listreceivedbyaccount is deprecated", self.nodes[0].listreceivedbyaccount)
101+
self.nodes[1].listreceivedbyaccount()
102+
103+
self.log.info("- listreceivedbylabel")
104+
self.nodes[0].listreceivedbylabel()
105+
self.nodes[1].listreceivedbylabel()
106+
107+
self.log.info("- move")
108+
assert_raises_rpc_error(-32, "move is deprecated", self.nodes[0].move, "label0", "label0b", 10)
109+
self.nodes[1].move("label1", "label1b", 10)
110+
29111
if __name__ == '__main__':
30112
DeprecatedRpcTest().main()

0 commit comments

Comments
 (0)