Skip to content

Commit 9472ca0

Browse files
committed
wallet: AvailableCoins, don't call 'wtx.tx->vout[i]' multiple times
1 parent 4ce235e commit 9472ca0

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/wallet/spend.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,27 @@ CoinsResult AvailableCoins(const CWallet& wallet,
165165
bool tx_from_me = CachedTxIsFromMe(wallet, wtx, ISMINE_ALL);
166166

167167
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) {
168+
const CTxOut& output = wtx.tx->vout[i];
169+
const COutPoint outpoint(wtxid, i);
170+
168171
// Only consider selected coins if add_inputs is false
169-
if (coinControl && !coinControl->m_add_inputs && !coinControl->IsSelected(COutPoint(entry.first, i))) {
172+
if (coinControl && !coinControl->m_add_inputs && !coinControl->IsSelected(outpoint)) {
170173
continue;
171174
}
172175

173-
if (wtx.tx->vout[i].nValue < nMinimumAmount || wtx.tx->vout[i].nValue > nMaximumAmount)
176+
if (output.nValue < nMinimumAmount || output.nValue > nMaximumAmount)
174177
continue;
175178

176-
if (coinControl && coinControl->HasSelected() && !coinControl->fAllowOtherInputs && !coinControl->IsSelected(COutPoint(entry.first, i)))
179+
if (coinControl && coinControl->HasSelected() && !coinControl->fAllowOtherInputs && !coinControl->IsSelected(outpoint))
177180
continue;
178181

179-
if (wallet.IsLockedCoin(entry.first, i))
182+
if (wallet.IsLockedCoin(wtxid, i))
180183
continue;
181184

182185
if (wallet.IsSpent(wtxid, i))
183186
continue;
184187

185-
isminetype mine = wallet.IsMine(wtx.tx->vout[i]);
188+
isminetype mine = wallet.IsMine(output);
186189

187190
if (mine == ISMINE_NO) {
188191
continue;
@@ -192,16 +195,16 @@ CoinsResult AvailableCoins(const CWallet& wallet,
192195
continue;
193196
}
194197

195-
std::unique_ptr<SigningProvider> provider = wallet.GetSolvingProvider(wtx.tx->vout[i].scriptPubKey);
198+
std::unique_ptr<SigningProvider> provider = wallet.GetSolvingProvider(output.scriptPubKey);
196199

197-
bool solvable = provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) : false;
200+
bool solvable = provider ? IsSolvable(*provider, output.scriptPubKey) : false;
198201
bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable));
199202
int input_bytes = GetTxSpendSize(wallet, wtx, i, (coinControl && coinControl->fAllowWatchOnly));
200-
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);
203+
result.coins.emplace_back(outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate);
201204

202205
// Checks the sum amount of all UTXO's.
203206
if (nMinimumSumAmount != MAX_MONEY) {
204-
nTotal += wtx.tx->vout[i].nValue;
207+
nTotal += output.nValue;
205208

206209
if (nTotal >= nMinimumSumAmount) {
207210
return result;

0 commit comments

Comments
 (0)