From 0bf8b56b292016860ea618df86e27428754e557d Mon Sep 17 00:00:00 2001 From: John Newbery Date: Tue, 26 Jun 2018 17:21:30 -0400 Subject: [PATCH] [RPC] [wallet] allow getbalance to use min_conf and watch_only without accounts. (cherry picked from commit 702ae1e21a09d8c31406839c4ea507c5fa276898) --- qa/rpc-tests/txn_doublespend.py | 4 ++-- src/wallet/rpcwallet.cpp | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/qa/rpc-tests/txn_doublespend.py b/qa/rpc-tests/txn_doublespend.py index 12d7f76dc..3f7a26134 100755 --- a/qa/rpc-tests/txn_doublespend.py +++ b/qa/rpc-tests/txn_doublespend.py @@ -75,7 +75,7 @@ class TxnMallTest(BitcoinTestFramework): assert_equal(tx1["confirmations"], 1) assert_equal(tx2["confirmations"], 1) # Node1's total balance should be its starting balance plus both transaction amounts: - assert_equal(self.nodes[1].getbalance(""), starting_balance - (tx1["amount"]+tx2["amount"])) + assert_equal(self.nodes[1].getbalance("*"), starting_balance - (tx1["amount"]+tx2["amount"])) else: assert_equal(tx1["confirmations"], 0) assert_equal(tx2["confirmations"], 0) @@ -105,7 +105,7 @@ class TxnMallTest(BitcoinTestFramework): assert_equal(self.nodes[0].getbalance("*"), expected) # Node1's total balance should be its starting balance plus the amount of the mutated send: - assert_equal(self.nodes[1].getbalance(""), starting_balance + (starting_balance - (mining_reward - 2))) + assert_equal(self.nodes[1].getbalance("*"), starting_balance + (starting_balance - (mining_reward - 2))) if __name__ == '__main__': TxnMallTest().main() diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d8df25f99..8eaf31e83 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -752,7 +752,7 @@ UniValue getbalance(const UniValue& params, bool fHelp) "getbalance ( \"account\" minconf includeWatchonly inZat )\n" "\nReturns the server's total available balance.\n" "\nArguments:\n" - "1. \"account\" (string, optional) DEPRECATED. If provided, it MUST be set to the empty string \"\" or to the string \"*\", either of which will give the total available balance. Passing any other string will result in an error.\n" + "1. (dummy) (string, optional) Remains for backward compatibility. Must be excluded or set to \"*\" or \"\".\n" "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" "3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n" "4. inZat (bool, optional, default=false) Get the result amount in " + MINOR_CURRENCY_UNIT + " (as an integer).\n" @@ -760,7 +760,7 @@ UniValue getbalance(const UniValue& params, bool fHelp) "amount (numeric) The total amount in " + CURRENCY_UNIT + "(or " + MINOR_CURRENCY_UNIT + " if inZat is true) received.\n" "\nExamples:\n" "\nThe total amount in the wallet\n" - + HelpExampleCli("getbalance", "") + + + HelpExampleCli("getbalance", "*") + "\nThe total amount in the wallet at least 5 blocks confirmed\n" + HelpExampleCli("getbalance", "\"*\" 6") + "\nAs a json rpc call\n" @@ -772,7 +772,10 @@ UniValue getbalance(const UniValue& params, bool fHelp) if (params.size() == 0) return ValueFromAmount(pwalletMain->GetBalance()); - const std::string* account = params[0].get_str() != "*" ? ¶ms[0].get_str() : nullptr; + const UniValue& dummy_value = params[0]; + if (!dummy_value.isNull() && dummy_value.get_str() != "*" && dummy_value.get_str() != "") { + throw JSONRPCError(RPC_INVALID_PARAMETER, "dummy first argument must be excluded or set to \"*\" or \"\"."); + } int nMinDepth = 1; if (params.size() > 1) @@ -782,7 +785,7 @@ UniValue getbalance(const UniValue& params, bool fHelp) if(params[2].get_bool()) filter = filter | ISMINE_WATCH_ONLY; - CAmount nBalance = pwalletMain->GetLegacyBalance(filter, nMinDepth, account); + CAmount nBalance = pwalletMain->GetBalance(filter, nMinDepth); if (params.size() > 3 && params[3].get_bool()) { return nBalance; } else {