From e81d95d435744e48615973dc22acce1a291bd20d Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Thu, 15 May 2025 15:31:16 -0700 Subject: [PATCH] wallet: Remove watchonly balances Descriptor wallets do not have mixed mine and watchonly, so there is no need to report a watchonly balance. --- src/wallet/receive.cpp | 8 +------- src/wallet/receive.h | 3 --- src/wallet/rpc/coins.cpp | 6 ++---- test/functional/wallet_balance.py | 6 +----- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/wallet/receive.cpp b/src/wallet/receive.cpp index 1ba85b6b2d..4c9ffc499d 100644 --- a/src/wallet/receive.cpp +++ b/src/wallet/receive.cpp @@ -263,13 +263,10 @@ Balance GetBalance(const CWallet& wallet, const int min_depth, bool avoid_reuse) const int tx_depth{wallet.GetTxDepthInMainChain(wtx)}; if (!wallet.IsSpent(outpoint) && (allow_used_addresses || !wallet.IsSpentKey(txo.GetTxOut().scriptPubKey))) { - // Get the amounts for mine and watchonly + // Get the amounts for mine CAmount credit_mine = 0; - CAmount credit_watchonly = 0; if (txo.GetIsMine() == ISMINE_SPENDABLE) { credit_mine = txo.GetTxOut().nValue; - } else if (txo.GetIsMine() == ISMINE_WATCH_ONLY) { - credit_watchonly = txo.GetTxOut().nValue; } else { // We shouldn't see any other isminetypes Assume(false); @@ -278,13 +275,10 @@ Balance GetBalance(const CWallet& wallet, const int min_depth, bool avoid_reuse) // Set the amounts in the return object if (wallet.IsTxImmatureCoinBase(wtx) && wtx.isConfirmed()) { ret.m_mine_immature += credit_mine; - ret.m_watchonly_immature += credit_watchonly; } else if (is_trusted && tx_depth >= min_depth) { ret.m_mine_trusted += credit_mine; - ret.m_watchonly_trusted += credit_watchonly; } else if (!is_trusted && wtx.InMempool()) { ret.m_mine_untrusted_pending += credit_mine; - ret.m_watchonly_untrusted_pending += credit_watchonly; } } } diff --git a/src/wallet/receive.h b/src/wallet/receive.h index 330fbf21a6..b995e21c95 100644 --- a/src/wallet/receive.h +++ b/src/wallet/receive.h @@ -49,9 +49,6 @@ struct Balance { CAmount m_mine_trusted{0}; //!< Trusted, at depth=GetBalance.min_depth or more CAmount m_mine_untrusted_pending{0}; //!< Untrusted, but in mempool (pending) CAmount m_mine_immature{0}; //!< Immature coinbases in the main chain - CAmount m_watchonly_trusted{0}; - CAmount m_watchonly_untrusted_pending{0}; - CAmount m_watchonly_immature{0}; }; Balance GetBalance(const CWallet& wallet, int min_depth = 0, bool avoid_reuse = true); diff --git a/src/wallet/rpc/coins.cpp b/src/wallet/rpc/coins.cpp index 16d93de121..29da5b60eb 100644 --- a/src/wallet/rpc/coins.cpp +++ b/src/wallet/rpc/coins.cpp @@ -171,7 +171,7 @@ RPCHelpMan getbalance() { {"dummy", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Remains for backward compatibility. Must be excluded or set to \"*\"."}, {"minconf", RPCArg::Type::NUM, RPCArg::Default{0}, "Only include transactions confirmed at least this many times."}, - {"include_watchonly", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Also include balance in watch-only addresses (see 'importaddress')"}, + {"include_watchonly", RPCArg::Type::BOOL, RPCArg::Default{false}, "No longer used"}, {"avoid_reuse", RPCArg::Type::BOOL, RPCArg::Default{true}, "(only available if avoid_reuse wallet flag is set) Do not include balance in dirty outputs; addresses are considered dirty if they have previously been used in a transaction."}, }, RPCResult{ @@ -203,13 +203,11 @@ RPCHelpMan getbalance() const auto min_depth{self.Arg("minconf")}; - bool include_watchonly = ParseIncludeWatchonly(request.params[2], *pwallet); - bool avoid_reuse = GetAvoidReuseFlag(*pwallet, request.params[3]); const auto bal = GetBalance(*pwallet, min_depth, avoid_reuse); - return ValueFromAmount(bal.m_mine_trusted + (include_watchonly ? bal.m_watchonly_trusted : 0)); + return ValueFromAmount(bal.m_mine_trusted); }, }; } diff --git a/test/functional/wallet_balance.py b/test/functional/wallet_balance.py index 91f58efc62..8b51b0442e 100755 --- a/test/functional/wallet_balance.py +++ b/test/functional/wallet_balance.py @@ -145,14 +145,10 @@ class WalletTest(BitcoinTestFramework): # getbalances expected_balances_0 = {'mine': {'immature': Decimal('0E-8'), 'trusted': Decimal('9.99'), # change from node 0's send - 'untrusted_pending': Decimal('60.0')}, - 'watchonly': {'immature': Decimal('5000'), - 'trusted': Decimal('50.0'), - 'untrusted_pending': Decimal('0E-8')}} + 'untrusted_pending': Decimal('60.0')}} expected_balances_1 = {'mine': {'immature': Decimal('0E-8'), 'trusted': Decimal('0E-8'), # node 1's send had an unsafe input 'untrusted_pending': Decimal('30.0') - fee_node_1}} # Doesn't include output of node 0's send since it was spent - del expected_balances_0["watchonly"] balances_0 = self.nodes[0].getbalances() balances_1 = self.nodes[1].getbalances() # remove lastprocessedblock keys (they will be tested later)