Skip to content

Commit 40537f0

Browse files
committed
[wallet] ListCoins: include watch-only for wallets without private keys
This makes them available in GUI coin selection.
1 parent 8021392 commit 40537f0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/wallet/wallet.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,20 +2160,24 @@ std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins(interfaces::Ch
21602160

21612161
for (const COutput& coin : availableCoins) {
21622162
CTxDestination address;
2163-
if (coin.fSpendable &&
2163+
if ((coin.fSpendable || (IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS) && coin.fSolvable)) &&
21642164
ExtractDestination(FindNonChangeParentOutput(*coin.tx->tx, coin.i).scriptPubKey, address)) {
21652165
result[address].emplace_back(std::move(coin));
21662166
}
21672167
}
21682168

21692169
std::vector<COutPoint> lockedCoins;
21702170
ListLockedCoins(lockedCoins);
2171+
// Include watch-only for wallets without private keys
2172+
const bool include_watch_only = IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
2173+
const isminetype is_mine_filter = include_watch_only ? ISMINE_WATCH_ONLY : ISMINE_SPENDABLE;
21712174
for (const COutPoint& output : lockedCoins) {
21722175
auto it = mapWallet.find(output.hash);
21732176
if (it != mapWallet.end()) {
21742177
int depth = it->second.GetDepthInMainChain();
21752178
if (depth >= 0 && output.n < it->second.tx->vout.size() &&
2176-
IsMine(it->second.tx->vout[output.n]) == ISMINE_SPENDABLE) {
2179+
IsMine(it->second.tx->vout[output.n]) == is_mine_filter
2180+
) {
21772181
CTxDestination address;
21782182
if (ExtractDestination(FindNonChangeParentOutput(*it->second.tx, output.n).scriptPubKey, address)) {
21792183
result[address].emplace_back(

0 commit comments

Comments
 (0)