Skip to content

Commit

Permalink
[wallet] ListCoins: include watch-only for wallets without private keys
Browse files Browse the repository at this point in the history
This makes them available in GUI coin selection.

Github-Pull: bitcoin#16944
Rebased-From: 40537f0
  • Loading branch information
Sjors authored and luke-jr committed Jan 3, 2020
1 parent 71d05f9 commit 36e5243
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2631,9 +2631,13 @@ std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins(interfaces::Ch

AvailableCoins(locked_chain, availableCoins);

// Include watch-only for wallets without private keys
const bool include_watch_only = IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
const isminetype is_mine_filter = include_watch_only ? ISMINE_WATCH_ONLY : ISMINE_SPENDABLE;

for (const COutput& coin : availableCoins) {
CTxDestination address;
if (coin.fSpendable &&
if ((coin.fSpendable || (include_watch_only && coin.fSolvable)) &&
ExtractDestination(FindNonChangeParentOutput(*coin.tx->tx, coin.i).scriptPubKey, address)) {
result[address].emplace_back(std::move(coin));
}
Expand All @@ -2646,7 +2650,7 @@ std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins(interfaces::Ch
if (it != mapWallet.end()) {
int depth = it->second.GetDepthInMainChain(locked_chain);
if (depth >= 0 && output.n < it->second.tx->vout.size() &&
IsMine(it->second.tx->vout[output.n]) == ISMINE_SPENDABLE) {
IsMine(it->second.tx->vout[output.n]) == is_mine_filter) {
CTxDestination address;
if (ExtractDestination(FindNonChangeParentOutput(*it->second.tx, output.n).scriptPubKey, address)) {
result[address].emplace_back(
Expand Down

0 comments on commit 36e5243

Please sign in to comment.