[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
This commit is contained in:
John Newbery 2018-04-16 13:57:13 -04:00
parent 3db1ba01c7
commit 3576ab1261
2 changed files with 140 additions and 2 deletions

View File

@ -206,6 +206,13 @@ UniValue getlabeladdress(const JSONRPCRequest& request)
return NullUniValue; return NullUniValue;
} }
if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "getaccountaddress") {
if (request.fHelp) {
throw std::runtime_error("getaccountaddress (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
}
throw JSONRPCError(RPC_METHOD_DEPRECATED, "getaccountaddress is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
}
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error( throw std::runtime_error(
"getlabeladdress \"label\" ( force ) \n" "getlabeladdress \"label\" ( force ) \n"
@ -306,6 +313,13 @@ UniValue setlabel(const JSONRPCRequest& request)
return NullUniValue; return NullUniValue;
} }
if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "setaccount") {
if (request.fHelp) {
throw std::runtime_error("setaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
}
throw JSONRPCError(RPC_METHOD_DEPRECATED, "setaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
}
if (request.fHelp || request.params.size() != 2) if (request.fHelp || request.params.size() != 2)
throw std::runtime_error( throw std::runtime_error(
"setlabel \"address\" \"label\"\n" "setlabel \"address\" \"label\"\n"
@ -353,6 +367,13 @@ UniValue getaccount(const JSONRPCRequest& request)
return NullUniValue; return NullUniValue;
} }
if (!IsDeprecatedRPCEnabled("accounts")) {
if (request.fHelp) {
throw std::runtime_error("getaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
}
throw JSONRPCError(RPC_METHOD_DEPRECATED, "getaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
}
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw std::runtime_error( throw std::runtime_error(
"getaccount \"address\"\n" "getaccount \"address\"\n"
@ -389,6 +410,13 @@ UniValue getaddressesbyaccount(const JSONRPCRequest& request)
return NullUniValue; return NullUniValue;
} }
if (!IsDeprecatedRPCEnabled("accounts")) {
if (request.fHelp) {
throw std::runtime_error("getaddressbyaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
}
throw JSONRPCError(RPC_METHOD_DEPRECATED, "getaddressesbyaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
}
if (request.fHelp || request.params.size() != 1) if (request.fHelp || request.params.size() != 1)
throw std::runtime_error( throw std::runtime_error(
"getaddressesbyaccount \"account\"\n" "getaddressesbyaccount \"account\"\n"
@ -744,6 +772,13 @@ UniValue getreceivedbylabel(const JSONRPCRequest& request)
return NullUniValue; return NullUniValue;
} }
if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "getreceivedbyaccount") {
if (request.fHelp) {
throw std::runtime_error("getreceivedbyaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
}
throw JSONRPCError(RPC_METHOD_DEPRECATED, "getreceivedbyaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
}
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
throw std::runtime_error( throw std::runtime_error(
"getreceivedbylabel \"label\" ( minconf )\n" "getreceivedbylabel \"label\" ( minconf )\n"
@ -913,6 +948,13 @@ UniValue movecmd(const JSONRPCRequest& request)
return NullUniValue; return NullUniValue;
} }
if (!IsDeprecatedRPCEnabled("accounts")) {
if (request.fHelp) {
throw std::runtime_error("move (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
}
throw JSONRPCError(RPC_METHOD_DEPRECATED, "move is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
}
if (request.fHelp || request.params.size() < 3 || request.params.size() > 5) if (request.fHelp || request.params.size() < 3 || request.params.size() > 5)
throw std::runtime_error( throw std::runtime_error(
"move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n" "move \"fromaccount\" \"toaccount\" amount ( minconf \"comment\" )\n"
@ -1609,6 +1651,13 @@ UniValue listreceivedbylabel(const JSONRPCRequest& request)
return NullUniValue; return NullUniValue;
} }
if (!IsDeprecatedRPCEnabled("accounts") && request.strMethod == "listreceivedbyaccount") {
if (request.fHelp) {
throw std::runtime_error("listreceivedbyaccount (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
}
throw JSONRPCError(RPC_METHOD_DEPRECATED, "listreceivedbyaccount is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
}
if (request.fHelp || request.params.size() > 3) if (request.fHelp || request.params.size() > 3)
throw std::runtime_error( throw std::runtime_error(
"listreceivedbylabel ( minconf include_empty include_watchonly)\n" "listreceivedbylabel ( minconf include_empty include_watchonly)\n"
@ -1908,6 +1957,13 @@ UniValue listaccounts(const JSONRPCRequest& request)
return NullUniValue; return NullUniValue;
} }
if (!IsDeprecatedRPCEnabled("accounts")) {
if (request.fHelp) {
throw std::runtime_error("listaccounts (Deprecated, will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts)");
}
throw JSONRPCError(RPC_METHOD_DEPRECATED, "listaccounts is deprecated and will be removed in V0.18. To use this command, start bitcoind with -deprecatedrpc=accounts.");
}
if (request.fHelp || request.params.size() > 2) if (request.fHelp || request.params.size() > 2)
throw std::runtime_error( throw std::runtime_error(
"listaccounts ( minconf include_watchonly)\n" "listaccounts ( minconf include_watchonly)\n"

View File

@ -4,12 +4,13 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test deprecation of RPC calls.""" """Test deprecation of RPC calls."""
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_raises_rpc_error
class DeprecatedRpcTest(BitcoinTestFramework): class DeprecatedRpcTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = True self.setup_clean_chain = True
self.extra_args = [[], ["-deprecatedrpc=validateaddress"]] self.extra_args = [[], ["-deprecatedrpc=validateaddress", "-deprecatedrpc=accounts"]]
def run_test(self): def run_test(self):
# This test should be used to verify correct behaviour of deprecated # This test should be used to verify correct behaviour of deprecated
@ -26,5 +27,86 @@ class DeprecatedRpcTest(BitcoinTestFramework):
not_dep_val = self.nodes[1].validateaddress(SOME_ADDRESS) not_dep_val = self.nodes[1].validateaddress(SOME_ADDRESS)
assert "ismine" in not_dep_val assert "ismine" in not_dep_val
self.log.info("Test accounts deprecation")
# The following account RPC methods are deprecated:
# - getaccount
# - getaccountaddress
# - getaddressesbyaccount
# - getreceivedbyaccount
# - listaccouts
# - listreceivedbyaccount
# - move
# - setaccount
#
# The following 'label' RPC methods are usable both with and without the
# -deprecatedrpc=accounts switch enabled.
# - getlabeladdress
# - getaddressesbylabel
# - getreceivedbylabel
# - listlabels
# - listreceivedbylabel
# - setlabel
#
address0 = self.nodes[0].getnewaddress()
self.nodes[0].generatetoaddress(101, address0)
address1 = self.nodes[1].getnewaddress()
self.nodes[1].generatetoaddress(101, address1)
self.log.info("- getaccount")
assert_raises_rpc_error(-32, "getaccount is deprecated", self.nodes[0].getaccount, address0)
self.nodes[1].getaccount(address1)
self.log.info("- setaccount")
assert_raises_rpc_error(-32, "setaccount is deprecated", self.nodes[0].setaccount, address0, "label0")
self.nodes[1].setaccount(address1, "label1")
self.log.info("- setlabel")
self.nodes[0].setlabel(address0, "label0")
self.nodes[1].setlabel(address1, "label1")
self.log.info("- getaccountaddress")
assert_raises_rpc_error(-32, "getaccountaddress is deprecated", self.nodes[0].getaccountaddress, "label0")
self.nodes[1].getaccountaddress("label1")
self.log.info("- getlabeladdress")
self.nodes[0].getlabeladdress("label0")
self.nodes[1].getlabeladdress("label1")
self.log.info("- getaddressesbyaccount")
assert_raises_rpc_error(-32, "getaddressesbyaccount is deprecated", self.nodes[0].getaddressesbyaccount, "label0")
self.nodes[1].getaddressesbyaccount("label1")
self.log.info("- getaddressesbylabel")
self.nodes[0].getaddressesbylabel("label0")
self.nodes[1].getaddressesbylabel("label1")
self.log.info("- getreceivedbyaccount")
assert_raises_rpc_error(-32, "getreceivedbyaccount is deprecated", self.nodes[0].getreceivedbyaccount, "label0")
self.nodes[1].getreceivedbyaccount("label1")
self.log.info("- getreceivedbylabel")
self.nodes[0].getreceivedbylabel("label0")
self.nodes[1].getreceivedbylabel("label1")
self.log.info("- listaccounts")
assert_raises_rpc_error(-32, "listaccounts is deprecated", self.nodes[0].listaccounts)
self.nodes[1].listaccounts()
self.log.info("- listlabels")
self.nodes[0].listlabels()
self.nodes[1].listlabels()
self.log.info("- listreceivedbyaccount")
assert_raises_rpc_error(-32, "listreceivedbyaccount is deprecated", self.nodes[0].listreceivedbyaccount)
self.nodes[1].listreceivedbyaccount()
self.log.info("- listreceivedbylabel")
self.nodes[0].listreceivedbylabel()
self.nodes[1].listreceivedbylabel()
self.log.info("- move")
assert_raises_rpc_error(-32, "move is deprecated", self.nodes[0].move, "label0", "label0b", 10)
self.nodes[1].move("label1", "label1b", 10)
if __name__ == '__main__': if __name__ == '__main__':
DeprecatedRpcTest().main() DeprecatedRpcTest().main()