mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-31 19:31:02 +02:00
wallet: Remove watchonly balances
Descriptor wallets do not have mixed mine and watchonly, so there is no need to report a watchonly balance.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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<int>("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);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user