diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 5a3762fe4f..f42c743a86 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2523,27 +2523,40 @@ set< set > CWallet::GetAddressGroupings() if (pcoin->vin.size() > 0 && (IsMine(pcoin->vin[0]) != ISMINE_NO)) { + bool any_mine = false; + // group all input addresses with each other for (auto const& txin : pcoin->vin) { CTxDestination address; - if(!ExtractDestination(mapWallet[txin.prevout.hash].vout[txin.prevout.n].scriptPubKey, address)) - continue; + + // If the input is not mine, ignore it. + if (IsMine(txin) == ISMINE_NO) continue; + + CScript& scriptPubKey = mapWallet[txin.prevout.hash].vout[txin.prevout.n].scriptPubKey; + + if (!ExtractDestination(scriptPubKey, address)) continue; + grouping.insert(address); + any_mine = true; } // group change with input addresses - for (auto const& txout : pcoin->vout) - if (IsChange(txout)) - { - CWalletTx tx = mapWallet[pcoin->vin[0].prevout.hash]; - CTxDestination txoutAddr; - if(!ExtractDestination(txout.scriptPubKey, txoutAddr)) - continue; - grouping.insert(txoutAddr); - } - groupings.insert(grouping); - grouping.clear(); + if (any_mine) { + for (auto const& txout : pcoin->vout) + if (IsChange(txout)) + { + CTxDestination txoutAddr; + if(!ExtractDestination(txout.scriptPubKey, txoutAddr)) + continue; + grouping.insert(txoutAddr); + } + } + + if (grouping.size() > 0) { + groupings.insert(grouping); + grouping.clear(); + } } // group lone addrs by themselves