diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -284,7 +284,7 @@ // Parse the label first so we don't generate a key if there's an error std::string label = LabelFromValue(request.params[0]); - bool force = request.strMethod == "getaccountaddress" ? true : false; + bool force = request.strMethod == "getaccountaddress"; if (!request.params[1].isNull()) { force = request.params[1].get_bool(); } @@ -1024,7 +1024,11 @@ return NullUniValue; } - if (request.fHelp || request.params.size() > 3) { + if (request.fHelp || + (request.params.size() > 3 && + IsDeprecatedRPCEnabled(gArgs, "accounts")) || + (request.params.size() != 0 && + !IsDeprecatedRPCEnabled(gArgs, "accounts"))) { throw std::runtime_error( "getbalance ( \"account\" minconf include_watchonly )\n" "\nIf account is not specified, returns the server's total " @@ -1040,7 +1044,10 @@ "The server total may be different to the balance in the default " "\"\" account.\n" "\nArguments:\n" - "1. \"account\" (string, optional) DEPRECATED. The account " + "1. \"account\" (string, optional) DEPRECATED. This " + "argument will be removed in v0.21. \n" + " To use this deprecated argument, start " + "bitcoind with -deprecatedrpc=accounts. The account " "string may be given as a\n" " specific account name to find the balance " "associated with wallet keys in\n" @@ -1062,10 +1069,16 @@ " has resulted in confusing outcomes, so it is " "recommended to avoid passing\n" " this argument.\n" - "2. minconf (numeric, optional, default=1) Only include " - "transactions confirmed at least this many times.\n" - "3. include_watchonly (bool, optional, default=false) Also include " - "balance in watch-only addresses (see 'importaddress')\n" + "2. minconf (numeric, optional, default=1) DEPRECATED. " + "Only valid when an account is specified. This argument will be " + "removed in V0.21. To use this deprecated argument, start bitcoind " + "with -deprecatedrpc=accounts. Only include transactions confirmed " + "at least this many times.\n" + "3. include_watchonly (bool, optional, default=false) DEPRECATED. " + "Only valid when an account is specified. This argument will be " + "removed in V0.21. To use this deprecated argument, start bitcoind " + "with -deprecatedrpc=accounts. Also include balance in watch-only " + "addresses (see 'importaddress')\n" "\nResult:\n" "amount (numeric) The total amount in " + CURRENCY_UNIT + @@ -1084,41 +1097,45 @@ LOCK2(cs_main, pwallet->cs_wallet); - const UniValue &account_value = request.params[0]; - const UniValue &minconf = request.params[1]; - const UniValue &include_watchonly = request.params[2]; + if (IsDeprecatedRPCEnabled(gArgs, "accounts")) { + const UniValue &account_value = request.params[0]; + const UniValue &minconf = request.params[1]; + const UniValue &include_watchonly = request.params[2]; - if (account_value.isNull()) { - if (!minconf.isNull()) { - throw JSONRPCError(RPC_INVALID_PARAMETER, - "getbalance minconf option is only currently " - "supported if an account is specified"); - } - if (!include_watchonly.isNull()) { - throw JSONRPCError( - RPC_INVALID_PARAMETER, - "getbalance include_watchonly option is only currently " - "supported if an account is specified"); + if (account_value.isNull()) { + if (!minconf.isNull()) { + throw JSONRPCError( + RPC_INVALID_PARAMETER, + "getbalance minconf option is only currently supported if " + "an account is specified"); + } + if (!include_watchonly.isNull()) { + throw JSONRPCError( + RPC_INVALID_PARAMETER, + "getbalance include_watchonly option is only currently " + "supported if an account is specified"); + } + return ValueFromAmount(pwallet->GetBalance()); } - return ValueFromAmount(pwallet->GetBalance()); - } - const std::string &account_param = account_value.get_str(); - const std::string *account = - account_param != "*" ? &account_param : nullptr; + const std::string &account_param = account_value.get_str(); + const std::string *account = + account_param != "*" ? &account_param : nullptr; - int nMinDepth = 1; - if (!minconf.isNull()) { - nMinDepth = minconf.get_int(); - } + int nMinDepth = 1; + if (!minconf.isNull()) { + nMinDepth = minconf.get_int(); + } + isminefilter filter = ISMINE_SPENDABLE; + if (!include_watchonly.isNull() && include_watchonly.get_bool()) { + filter = filter | ISMINE_WATCH_ONLY; + } - isminefilter filter = ISMINE_SPENDABLE; - if (!include_watchonly.isNull() && include_watchonly.get_bool()) { - filter = filter | ISMINE_WATCH_ONLY; + return ValueFromAmount( + pwallet->GetLegacyBalance(filter, nMinDepth, account)); } - return ValueFromAmount( - pwallet->GetLegacyBalance(filter, nMinDepth, account)); + return ValueFromAmount(pwallet->GetBalance()); } static UniValue getunconfirmedbalance(const Config &config, @@ -1347,12 +1364,84 @@ return NullUniValue; } - if (request.fHelp || request.params.size() < 2 || - request.params.size() > 5) { - throw std::runtime_error( + std::string help_text; + if (!IsDeprecatedRPCEnabled(gArgs, "accounts")) { + help_text = "sendmany \"fromaccount\" {\"address\":amount,...} ( minconf " "\"comment\" [\"address\",...] )\n" "\nSend multiple times. Amounts are double-precision floating " + "point numbers.\n" + "Note that the \"fromaccount\" argument has been removed in V0.20. " + "To use this RPC with a \"fromaccount\" argument, restart\n" + "bitcoind with -deprecatedrpc=accounts\n" + + HelpRequiringPassphrase(pwallet) + + "\n" + "\nArguments:\n" + "1. \"dummy\" (string, required) Must be set to \"\" " + "for backwards compatibility.\n" + "2. \"amounts\" (string, required) A json object with " + "addresses and amounts\n" + " {\n" + " \"address\":amount (numeric or string) The bitcoin " + "address is the key, the numeric amount (can be string) in " + + CURRENCY_UNIT + + " is the value\n" + " ,...\n" + " }\n" + "3. minconf (numeric, optional, default=1) Only " + "use the balance confirmed at least this many times.\n" + "4. \"comment\" (string, optional) A comment\n" + "5. subtractfeefrom (array, optional) A json array with " + "addresses.\n" + " The fee will be equally deducted from " + "the amount of each selected address.\n" + " Those recipients will receive less " + "bitcoins than you enter in their corresponding amount field.\n" + " If no addresses are specified here, " + "the sender pays the fee.\n" + " [\n" + " \"address\" (string) Subtract fee from this " + "address\n" + " ,...\n" + " ]\n" + "\nResult:\n" + "\"txid\" (string) The transaction id for the " + "send. Only 1 transaction is created regardless of \n" + " the number of addresses.\n" + "\nExamples:\n" + "\nSend two amounts to two different addresses:\n" + + HelpExampleCli("sendmany", + "\"\" " + "\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," + "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}" + "\"") + + "\nSend two amounts to two different addresses setting the " + "confirmation and comment:\n" + + HelpExampleCli("sendmany", + "\"\" " + "\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," + "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" " + "6 \"testing\"") + + "\nSend two amounts to two different addresses, subtract fee from " + "amount:\n" + + HelpExampleCli("sendmany", + "\"\" " + "\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," + "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" " + "1 \"\" " + "\"[\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\"," + "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\"]\"") + + "\nAs a json rpc call\n" + + HelpExampleRpc("sendmany", + "\"\", " + "\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," + "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\"," + " 6, \"testing\""); + } else { + help_text = + "sendmany \"\" \"fromaccount\" {\"address\":amount,...} ( " + "minconf \"comment\" [\"address\",...])\n" + "\nSend multiple times. Amounts are double-precision floating " "point numbers." + HelpRequiringPassphrase(pwallet) + "\n" @@ -1417,7 +1506,12 @@ "\"\", " "\"{\\\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\\\":0.01," "\\\"1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\"," - " 6, \"testing\"")); + " 6, \"testing\""); + } + + if (request.fHelp || request.params.size() < 2 || + request.params.size() > 5) { + throw std::runtime_error(help_text); } // Make sure the results are valid at least up to the most recent block @@ -1432,6 +1526,11 @@ "Error: Peer-to-peer functionality missing or disabled"); } + if (!IsDeprecatedRPCEnabled(gArgs, "accounts") && + !request.params[0].get_str().empty()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, + "Dummy value must be set to \"\""); + } std::string strAccount = LabelFromValue(request.params[0]); UniValue sendTo = request.params[1].get_obj(); int nMinDepth = 1; @@ -1958,7 +2057,9 @@ (::IsMine(*pwallet, s.destination) & ISMINE_WATCH_ONLY)) { entry.pushKV("involvesWatchonly", true); } - entry.pushKV("account", strSentAccount); + if (IsDeprecatedRPCEnabled(gArgs, "accounts")) { + entry.pushKV("account", strSentAccount); + } MaybePushAddress(entry, s.destination); entry.pushKV("category", "send"); entry.pushKV("amount", ValueFromAmount(-s.amount)); @@ -1989,7 +2090,9 @@ (::IsMine(*pwallet, r.destination) & ISMINE_WATCH_ONLY)) { entry.pushKV("involvesWatchonly", true); } - entry.pushKV("account", account); + if (IsDeprecatedRPCEnabled(gArgs, "accounts")) { + entry.pushKV("account", account); + } MaybePushAddress(entry, r.destination); if (wtx.IsCoinBase()) { if (wtx.GetDepthInMainChain() < 1) { @@ -2026,7 +2129,9 @@ entry.pushKV("category", "move"); entry.pushKV("time", acentry.nTime); entry.pushKV("amount", ValueFromAmount(acentry.nCreditDebit)); - entry.pushKV("otheraccount", acentry.strOtherAccount); + if (IsDeprecatedRPCEnabled(gArgs, "accounts")) { + entry.pushKV("otheraccount", acentry.strOtherAccount); + } entry.pushKV("comment", acentry.strComment); ret.push_back(entry); } @@ -2040,14 +2145,89 @@ return NullUniValue; } - if (request.fHelp || request.params.size() > 4) { - throw std::runtime_error( + std::string help_text{}; + if (!IsDeprecatedRPCEnabled(gArgs, "accounts")) { + help_text = + "listtransactions (dummy count skip include_watchonly)\n" + "\nReturns up to 'count' most recent transactions skipping the " + "first 'from' transactions for account 'account'.\n" + "Note that the \"account\" argument and \"otheraccount\" return " + "value have been removed in V0.20. To use this RPC with an " + "\"account\" argument, restart\n" + "bitcoind with -deprecatedrpc=accounts\n" + "\nArguments:\n" + "1. \"dummy\" (string, optional) If set, should be \"*\" for " + "backwards compatibility.\n" + "2. count (numeric, optional, default=10) The number of " + "transactions to return\n" + "3. skip (numeric, optional, default=0) The number of " + "transactions to skip\n" + "4. include_watchonly (bool, optional, default=false) Include " + "transactions to watch-only addresses (see 'importaddress')\n" + "\nResult:\n" + "[\n" + " {\n" + " \"address\":\"address\", (string) The bitcoin address of " + "the transaction.\n" + " \"category\":\"send|receive\", (string) The transaction " + "category.\n" + " \"amount\": x.xxx, (numeric) The amount in " + + CURRENCY_UNIT + + ". This is negative for the 'send' category, and is positive\n" + " for the 'receive' " + "category,\n" + " \"label\": \"label\", (string) A comment for the " + "address/transaction, if any\n" + " \"vout\": n, (numeric) the vout value\n" + " \"fee\": x.xxx, (numeric) The amount of the fee " + "in " + + CURRENCY_UNIT + + ". This is negative and only available for the \n" + " 'send' category of " + "transactions.\n" + " \"confirmations\": n, (numeric) The number of " + "confirmations for the transaction. Negative confirmations " + "indicate the\n" + " transaction conflicts " + "with the block chain\n" + " \"trusted\": xxx, (bool) Whether we consider the " + "outputs of this unconfirmed transaction safe to spend.\n" + " \"blockhash\": \"hashvalue\", (string) The block hash " + "containing the transaction.\n" + " \"blockindex\": n, (numeric) The index of the " + "transaction in the block that includes it.\n" + " \"blocktime\": xxx, (numeric) The block time in " + "seconds since epoch (1 Jan 1970 GMT).\n" + " \"txid\": \"transactionid\", (string) The transaction id.\n" + " \"time\": xxx, (numeric) The transaction time in " + "seconds since epoch (midnight Jan 1 1970 GMT).\n" + " \"timereceived\": xxx, (numeric) The time received in " + "seconds since epoch (midnight Jan 1 1970 GMT).\n" + " \"comment\": \"...\", (string) If a comment is " + "associated with the transaction.\n" + " \"abandoned\": xxx (bool) 'true' if the transaction " + "has been abandoned (inputs are respendable). Only available for " + "the \n" + " 'send' category of " + "transactions.\n" + " }\n" + "]\n" + + "\nExamples:\n" + "\nList the most recent 10 transactions in the systems\n" + + HelpExampleCli("listtransactions", "") + + "\nList transactions 100 to 120\n" + + HelpExampleCli("listtransactions", "\"*\" 20 100") + + "\nAs a json rpc call\n" + + HelpExampleRpc("listtransactions", "\"*\", 20, 100"); + } else { + help_text = "listtransactions ( \"account\" count skip include_watchonly)\n" "\nReturns up to 'count' most recent transactions skipping the " "first 'from' transactions for account 'account'.\n" "\nArguments:\n" - "1. \"account\" (string, optional) DEPRECATED. The account " - "name. Should be \"*\".\n" + "1. \"account\" (string, optional) DEPRECATED. This argument " + "will be removed in V0.21. The account name. Should be \"*\".\n" "2. count (numeric, optional, default=10) The number of " "transactions to return\n" "3. skip (numeric, optional, default=0) The number of " @@ -2057,8 +2237,9 @@ "\nResult:\n" "[\n" " {\n" - " \"account\":\"accountname\", (string) DEPRECATED. The " - "account name associated with the transaction. \n" + " \"account\":\"accountname\", (string) DEPRECATED. This " + "field will be removed in V0.21. The account name associated with " + "the transaction. \n" " It will be \"\" " "for the default account.\n" " \"address\":\"address\", (string) The bitcoin address of " @@ -2118,8 +2299,9 @@ "'receive' category of transactions.\n" " \"comment\": \"...\", (string) If a comment is " "associated with the transaction.\n" - " \"otheraccount\": \"accountname\", (string) DEPRECATED. For " - "the 'move' category of transactions, the account the funds came \n" + " \"otheraccount\": \"accountname\", (string) DEPRECATED. This " + "field will be removed in V0.21. For the 'move' category of " + "transactions, the account the funds came \n" " from (for receiving " "funds, positive amounts), or went to (for sending funds,\n" " negative amounts).\n" @@ -2137,7 +2319,10 @@ "\nList transactions 100 to 120\n" + HelpExampleCli("listtransactions", "\"*\" 20 100") + "\nAs a json rpc call\n" + - HelpExampleRpc("listtransactions", "\"*\", 20, 100")); + HelpExampleRpc("listtransactions", "\"*\", 20, 100"); + } + if (request.fHelp || request.params.size() > 4) { + throw std::runtime_error(help_text); } // Make sure the results are valid at least up to the most recent block @@ -2149,8 +2334,11 @@ std::string strAccount = "*"; if (!request.params[0].isNull()) { strAccount = request.params[0].get_str(); + if (!IsDeprecatedRPCEnabled(gArgs, "accounts") && strAccount != "*") { + throw JSONRPCError(RPC_INVALID_PARAMETER, + "Dummy value must be set to \"*\""); + } } - int nCount = 10; if (!request.params[1].isNull()) { nCount = request.params[1].get_int(); @@ -2183,9 +2371,11 @@ if (pwtx != nullptr) { ListTransactions(pwallet, *pwtx, strAccount, 0, true, ret, filter); } - CAccountingEntry *const pacentry = (*it).second.second; - if (pacentry != nullptr) { - AcentryToJSON(*pacentry, strAccount, ret); + if (IsDeprecatedRPCEnabled(gArgs, "accounts")) { + CAccountingEntry *const pacentry = (*it).second.second; + if (pacentry != nullptr) { + AcentryToJSON(*pacentry, strAccount, ret); + } } if ((int)ret.size() >= (nCount + nFrom)) { @@ -2380,7 +2570,9 @@ "\nResult:\n" "{\n" " \"transactions\": [\n" - " \"account\":\"accountname\", (string) DEPRECATED. The " + " \"account\":\"accountname\", (string) DEPRECATED. This " + "field will be removed in V0.21. To see this deprecated field, " + "start bitcoind with -deprecatedrpc=accounts. The " "account name associated with the transaction. Will be \"\" for " "the default account.\n" " \"address\":\"address\", (string) The bitcoin address of " @@ -2602,8 +2794,10 @@ " \"details\" : [\n" " {\n" " \"account\" : \"accountname\", (string) DEPRECATED. " - "The account name involved in the transaction, can be \"\" for the " - "default account.\n" + "This field will be removed in a V0.21. To see this deprecated " + "field, start bitcoind with -deprecatedrpc=accounts. The account " + "name involved in the transaction, can be \"\" for the default " + "account.\n" " \"address\" : \"address\", (string) The bitcoin " "address involved in the transaction\n" " \"category\" : \"send|receive\", (string) The category, " @@ -3770,8 +3964,10 @@ " \"address\" : \"address\", (string) the bitcoin address\n" " \"label\" : \"label\", (string) The associated label, " "or \"\" for the default label\n" - " \"account\" : \"account\", (string) DEPRECATED. Backwards " - "compatible alias for label.\n" + " \"account\" : \"account\", (string) DEPRECATED. This field " + "will be removed in v0.21. To see this deprecated field, start " + "bitcoind with -deprecatedrpc=accounts. The associated account, or " + "\"\" for the default account\n" " \"scriptPubKey\" : \"key\", (string) the script key\n" " \"amount\" : x.xxx, (numeric) the transaction output " "amount in " + @@ -3908,7 +4104,10 @@ if (pwallet->mapAddressBook.count(address)) { entry.pushKV("label", pwallet->mapAddressBook[address].name); - entry.pushKV("account", pwallet->mapAddressBook[address].name); + if (IsDeprecatedRPCEnabled(gArgs, "accounts")) { + entry.pushKV("account", + pwallet->mapAddressBook[address].name); + } } if (scriptPubKey.IsPayToScriptHash()) { @@ -4566,7 +4765,11 @@ "(\"ismine\", \"iswatchonly\", \"account\").\n" " \"iscompressed\" : true|false, (boolean) If the address is " "compressed\n" - " \"account\" : \"account\" (string) The account " + " \"label\" : \"label\" (string) The label associated " + "with the address, \"\" is the default account\n" + " \"account\" : \"account\" (string) DEPRECATED. This " + "field will be removed in V0.21. To see this deprecated field, " + "start bitcoind with -deprecatedrpc=accounts. The account " "associated with the address, \"\" is the default account\n" " \"timestamp\" : timestamp, (number, optional) The creation " "time of the key if available in seconds since epoch (Jan 1 1970 " @@ -4620,7 +4823,10 @@ UniValue detail = DescribeWalletAddress(pwallet, dest); ret.pushKVs(detail); if (pwallet->mapAddressBook.count(dest)) { - ret.pushKV("account", pwallet->mapAddressBook[dest].name); + ret.pushKV("label", pwallet->mapAddressBook[dest].name); + if (IsDeprecatedRPCEnabled(gArgs, "accounts")) { + ret.pushKV("account", pwallet->mapAddressBook[dest].name); + } } const CKeyMetadata *meta = nullptr; CKeyID key_id = GetKeyForDestination(*pwallet, dest); @@ -4878,7 +5084,7 @@ { "wallet", "listlockunspent", listlockunspent, {} }, { "wallet", "listreceivedbyaddress", listreceivedbyaddress, {"minconf","include_empty","include_watchonly","address_filter"} }, { "wallet", "listsinceblock", listsinceblock, {"blockhash","target_confirmations","include_watchonly","include_removed"} }, - { "wallet", "listtransactions", listtransactions, {"account","count","skip","include_watchonly"} }, + { "wallet", "listtransactions", listtransactions, {"account|dummy","count","skip","include_watchonly"} }, { "wallet", "listunspent", listunspent, {"minconf","maxconf","addresses","include_unsafe","query_options"} }, { "wallet", "listwallets", listwallets, {} }, { "wallet", "loadwallet", loadwallet, {"filename"} }, @@ -4886,7 +5092,7 @@ { "wallet", "rescanblockchain", rescanblockchain, {"start_height", "stop_height"} }, { "wallet", "sethdseed", sethdseed, {"newkeypool","seed"} }, { "wallet", "sendfrom", sendfrom, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} }, - { "wallet", "sendmany", sendmany, {"fromaccount","amounts","minconf","comment","subtractfeefrom"} }, + { "wallet", "sendmany", sendmany, {"fromaccount|dummy","amounts","minconf","comment","subtractfeefrom"} }, { "wallet", "sendtoaddress", sendtoaddress, {"address","amount","comment","comment_to","subtractfeefromamount"} }, { "wallet", "settxfee", settxfee, {"amount"} }, { "wallet", "signmessage", signmessage, {"address","message"} }, diff --git a/test/functional/wallet_labels.py b/test/functional/wallet_labels.py --- a/test/functional/wallet_labels.py +++ b/test/functional/wallet_labels.py @@ -6,26 +6,39 @@ RPCs tested are: - getlabeladdress - - getaddressesbyaccount + - getaddressesbyaccount/getaddressesbylabel - listaddressgroupings - setlabel - sendfrom (with account arguments) - move (with account arguments) + +Run the test twice - once using the accounts API and once using the labels API. +The accounts API test can be removed in V0.21. """ from collections import defaultdict from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal +from test_framework.util import assert_equal, assert_raises_rpc_error class WalletLabelsTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True - self.num_nodes = 1 - self.extra_args = [['-deprecatedrpc=accounts']] + self.num_nodes = 2 + self.extra_args = [['-deprecatedrpc=accounts'], []] + + def setup_network(self): + """Don't connect nodes.""" + self.setup_nodes() def run_test(self): - node = self.nodes[0] + """Run the test twice - once using the accounts API and once using the labels API.""" + self.log.info("Test accounts API") + self._run_subtest(True, self.nodes[0]) + self.log.info("Test labels API") + self._run_subtest(False, self.nodes[1]) + + def _run_subtest(self, accounts_api, node): # Check that there's no UTXO on any of the nodes assert_equal(len(node.listunspent()), 0) @@ -74,7 +87,8 @@ # Create labels and make sure subsequent label API calls # recognize the label/address associations. - labels = [Label(name) for name in ("a", "b", "c", "d", "e")] + labels = [Label(name, accounts_api) + for name in ("a", "b", "c", "d", "e")] for label in labels: label.add_receive_address( node.getlabeladdress(label=label.name, force=True)) @@ -99,21 +113,23 @@ # Check that sendfrom label reduces listaccounts balances. for i, label in enumerate(labels): - to_label = labels[(i+1) % len(labels)] + to_label = labels[(i + 1) % len(labels)] node.sendfrom(label.name, to_label.receive_address, amount_to_send) node.generate(1) for label in labels: label.add_receive_address(node.getlabeladdress(label.name)) label.verify(node) assert_equal(node.getreceivedbylabel(label.name), 2) - node.move(label.name, "", node.getbalance(label.name)) + if accounts_api: + node.move(label.name, "", node.getbalance(label.name)) label.verify(node) node.generate(101) expected_account_balances = {"": 5200 + fee} for label in labels: expected_account_balances[label.name] = 0 - assert_equal(node.listaccounts(), expected_account_balances) - assert_equal(node.getbalance(""), 5200 + fee) + if accounts_api: + assert_equal(node.listaccounts(), expected_account_balances) + assert_equal(node.getbalance(""), 5200 + fee) # Check that setlabel can assign a label to a new unused address. for label in labels: @@ -121,7 +137,11 @@ node.setlabel(address, label.name) label.add_address(address) label.verify(node) - assert address not in node.getaddressesbyaccount("") + if accounts_api: + assert(address not in node.getaddressesbyaccount("")) + else: + assert_raises_rpc_error(-11, "No addresses with label", + node.getaddressesbylabel, "") # Check that addmultisigaddress can assign labels. for label in labels: @@ -135,8 +155,9 @@ label.verify(node) node.sendfrom("", multisig_address, 50) node.generate(101) - for label in labels: - assert_equal(node.getbalance(label.name), 50) + if accounts_api: + for label in labels: + assert_equal(node.getbalance(label.name), 50) # Check that setlabel can change the label of an address from a # different label. @@ -156,9 +177,10 @@ class Label: - def __init__(self, name): + def __init__(self, name, accounts_api): # Label name self.name = name + self.accounts_api = accounts_api # Current receiving address associated with this label. self.receive_address = None # List of all addresses assigned with this label @@ -184,13 +206,17 @@ node.getaddressinfo(address)['labels'][0], {"name": self.name, "purpose": self.purpose[address]}) - assert_equal(node.getaccount(address), self.name) + if self.accounts_api: + assert_equal(node.getaccount(address), self.name) + else: + assert_equal(node.getaddressinfo(address)['label'], self.name) assert_equal( node.getaddressesbylabel(self.name), {address: {"purpose": self.purpose[address]} for address in self.addresses}) - assert_equal( - set(node.getaddressesbyaccount(self.name)), set(self.addresses)) + if self.accounts_api: + assert_equal(set(node.getaddressesbyaccount( + self.name)), set(self.addresses)) def change_label(node, address, old_label, new_label):