Skip to content

Commit e81d95d

Browse files
committed
wallet: Remove watchonly balances
Descriptor wallets do not have mixed mine and watchonly, so there is no need to report a watchonly balance.
1 parent d20dc9c commit e81d95d

File tree

4 files changed

+4
-19
lines changed

4 files changed

+4
-19
lines changed

src/wallet/receive.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,10 @@ Balance GetBalance(const CWallet& wallet, const int min_depth, bool avoid_reuse)
263263
const int tx_depth{wallet.GetTxDepthInMainChain(wtx)};
264264

265265
if (!wallet.IsSpent(outpoint) && (allow_used_addresses || !wallet.IsSpentKey(txo.GetTxOut().scriptPubKey))) {
266-
// Get the amounts for mine and watchonly
266+
// Get the amounts for mine
267267
CAmount credit_mine = 0;
268-
CAmount credit_watchonly = 0;
269268
if (txo.GetIsMine() == ISMINE_SPENDABLE) {
270269
credit_mine = txo.GetTxOut().nValue;
271-
} else if (txo.GetIsMine() == ISMINE_WATCH_ONLY) {
272-
credit_watchonly = txo.GetTxOut().nValue;
273270
} else {
274271
// We shouldn't see any other isminetypes
275272
Assume(false);
@@ -278,13 +275,10 @@ Balance GetBalance(const CWallet& wallet, const int min_depth, bool avoid_reuse)
278275
// Set the amounts in the return object
279276
if (wallet.IsTxImmatureCoinBase(wtx) && wtx.isConfirmed()) {
280277
ret.m_mine_immature += credit_mine;
281-
ret.m_watchonly_immature += credit_watchonly;
282278
} else if (is_trusted && tx_depth >= min_depth) {
283279
ret.m_mine_trusted += credit_mine;
284-
ret.m_watchonly_trusted += credit_watchonly;
285280
} else if (!is_trusted && wtx.InMempool()) {
286281
ret.m_mine_untrusted_pending += credit_mine;
287-
ret.m_watchonly_untrusted_pending += credit_watchonly;
288282
}
289283
}
290284
}

src/wallet/receive.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ struct Balance {
4949
CAmount m_mine_trusted{0}; //!< Trusted, at depth=GetBalance.min_depth or more
5050
CAmount m_mine_untrusted_pending{0}; //!< Untrusted, but in mempool (pending)
5151
CAmount m_mine_immature{0}; //!< Immature coinbases in the main chain
52-
CAmount m_watchonly_trusted{0};
53-
CAmount m_watchonly_untrusted_pending{0};
54-
CAmount m_watchonly_immature{0};
5552
};
5653
Balance GetBalance(const CWallet& wallet, int min_depth = 0, bool avoid_reuse = true);
5754

src/wallet/rpc/coins.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ RPCHelpMan getbalance()
171171
{
172172
{"dummy", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "Remains for backward compatibility. Must be excluded or set to \"*\"."},
173173
{"minconf", RPCArg::Type::NUM, RPCArg::Default{0}, "Only include transactions confirmed at least this many times."},
174-
{"include_watchonly", RPCArg::Type::BOOL, RPCArg::DefaultHint{"true for watch-only wallets, otherwise false"}, "Also include balance in watch-only addresses (see 'importaddress')"},
174+
{"include_watchonly", RPCArg::Type::BOOL, RPCArg::Default{false}, "No longer used"},
175175
{"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."},
176176
},
177177
RPCResult{
@@ -203,13 +203,11 @@ RPCHelpMan getbalance()
203203

204204
const auto min_depth{self.Arg<int>("minconf")};
205205

206-
bool include_watchonly = ParseIncludeWatchonly(request.params[2], *pwallet);
207-
208206
bool avoid_reuse = GetAvoidReuseFlag(*pwallet, request.params[3]);
209207

210208
const auto bal = GetBalance(*pwallet, min_depth, avoid_reuse);
211209

212-
return ValueFromAmount(bal.m_mine_trusted + (include_watchonly ? bal.m_watchonly_trusted : 0));
210+
return ValueFromAmount(bal.m_mine_trusted);
213211
},
214212
};
215213
}

test/functional/wallet_balance.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,10 @@ def test_balances(*, fee_node_1=0):
145145
# getbalances
146146
expected_balances_0 = {'mine': {'immature': Decimal('0E-8'),
147147
'trusted': Decimal('9.99'), # change from node 0's send
148-
'untrusted_pending': Decimal('60.0')},
149-
'watchonly': {'immature': Decimal('5000'),
150-
'trusted': Decimal('50.0'),
151-
'untrusted_pending': Decimal('0E-8')}}
148+
'untrusted_pending': Decimal('60.0')}}
152149
expected_balances_1 = {'mine': {'immature': Decimal('0E-8'),
153150
'trusted': Decimal('0E-8'), # node 1's send had an unsafe input
154151
'untrusted_pending': Decimal('30.0') - fee_node_1}} # Doesn't include output of node 0's send since it was spent
155-
del expected_balances_0["watchonly"]
156152
balances_0 = self.nodes[0].getbalances()
157153
balances_1 = self.nodes[1].getbalances()
158154
# remove lastprocessedblock keys (they will be tested later)

0 commit comments

Comments
 (0)