diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 79c8f064c05..78d3ad4b889 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -165,24 +165,27 @@ CoinsResult AvailableCoins(const CWallet& wallet, bool tx_from_me = CachedTxIsFromMe(wallet, wtx, ISMINE_ALL); for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) { + const CTxOut& output = wtx.tx->vout[i]; + const COutPoint outpoint(wtxid, i); + // Only consider selected coins if add_inputs is false - if (coinControl && !coinControl->m_add_inputs && !coinControl->IsSelected(COutPoint(entry.first, i))) { + if (coinControl && !coinControl->m_add_inputs && !coinControl->IsSelected(outpoint)) { continue; } - if (wtx.tx->vout[i].nValue < nMinimumAmount || wtx.tx->vout[i].nValue > nMaximumAmount) + if (output.nValue < nMinimumAmount || output.nValue > nMaximumAmount) continue; - if (coinControl && coinControl->HasSelected() && !coinControl->fAllowOtherInputs && !coinControl->IsSelected(COutPoint(entry.first, i))) + if (coinControl && coinControl->HasSelected() && !coinControl->fAllowOtherInputs && !coinControl->IsSelected(outpoint)) continue; - if (wallet.IsLockedCoin(entry.first, i)) + if (wallet.IsLockedCoin(wtxid, i)) continue; if (wallet.IsSpent(wtxid, i)) continue; - isminetype mine = wallet.IsMine(wtx.tx->vout[i]); + isminetype mine = wallet.IsMine(output); if (mine == ISMINE_NO) { continue; @@ -192,16 +195,16 @@ CoinsResult AvailableCoins(const CWallet& wallet, continue; } - std::unique_ptr provider = wallet.GetSolvingProvider(wtx.tx->vout[i].scriptPubKey); + std::unique_ptr provider = wallet.GetSolvingProvider(output.scriptPubKey); - bool solvable = provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) : false; + bool solvable = provider ? IsSolvable(*provider, output.scriptPubKey) : false; bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable)); int input_bytes = GetTxSpendSize(wallet, wtx, i, (coinControl && coinControl->fAllowWatchOnly)); - result.coins.emplace_back(COutPoint(wtx.GetHash(), i), wtx.tx->vout.at(i), nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate); + result.coins.emplace_back(outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate); // Checks the sum amount of all UTXO's. if (nMinimumSumAmount != MAX_MONEY) { - nTotal += wtx.tx->vout[i].nValue; + nTotal += output.nValue; if (nTotal >= nMinimumSumAmount) { return result;