Fixes https://github.com/bitcoin-core/gui/issues/688 and #26687.
First Issue Description (https://github.com/bitcoin-core/gui/issues/688):
The previous behavior for getAvailableBalance
, when the coin control had selected coins, was to return the sum of them. Instead, we are currently returning the wallet’s available total balance minus the selected coins total amount.
Reason:
Missed to update the GetAvailableBalance
function to include the coin control selected coins on #25685.
Context:
Since #25685 we skip the selected coins inside AvailableCoins
, the reason is that there is no need to waste resources walking through the entire wallet’s txes map just to get coins that could have gotten by just doing a simple mapWallet.find
).
Places Where This Generates Issues (only when the user manually select coins via coin control):
- The GUI balance check prior the transaction creation process.
- The GUI “useAvailableBalance” functionality.
Note 1: As the GUI uses a balance cache since https://github.com/bitcoin-core/gui/pull/598, this issue does not affect the regular spending process. Only arises when the user manually select coins.
Note 2:
Added test coverage for the useAvailableBalance
functionality.
Second Issue Description (https://github.com/bitcoin/bitcoin/issues/26687):
As we are using a cached balance on WalletModel::getAvailableBalance
,
the function needs to include the watch-only available balance for wallets
with private keys disabled.