wallet: AvailableCoins, don't call 'wtx.tx->vout[i]' multiple times
This commit is contained in:
1 file changed
+12
-9
+12
-9
@@ -165,24 +165,27 @@ CoinsResult AvailableCoins(const CWallet& wallet,
|
|||||||
bool tx_from_me = CachedTxIsFromMe(wallet, wtx, ISMINE_ALL);
|
bool tx_from_me = CachedTxIsFromMe(wallet, wtx, ISMINE_ALL);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) {
|
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
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wtx.tx->vout[i].nValue < nMinimumAmount || wtx.tx->vout[i].nValue > nMaximumAmount)
|
if (output.nValue < nMinimumAmount || output.nValue > nMaximumAmount)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (coinControl && coinControl->HasSelected() && !coinControl->fAllowOtherInputs && !coinControl->IsSelected(COutPoint(entry.first, i)))
|
if (coinControl && coinControl->HasSelected() && !coinControl->fAllowOtherInputs && !coinControl->IsSelected(outpoint))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (wallet.IsLockedCoin(entry.first, i))
|
if (wallet.IsLockedCoin(wtxid, i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (wallet.IsSpent(wtxid, i))
|
if (wallet.IsSpent(wtxid, i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
isminetype mine = wallet.IsMine(wtx.tx->vout[i]);
|
isminetype mine = wallet.IsMine(output);
|
||||||
|
|
||||||
if (mine == ISMINE_NO) {
|
if (mine == ISMINE_NO) {
|
||||||
continue;
|
continue;
|
||||||
@@ -192,16 +195,16 @@ CoinsResult AvailableCoins(const CWallet& wallet,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<SigningProvider> provider = wallet.GetSolvingProvider(wtx.tx->vout[i].scriptPubKey);
|
std::unique_ptr<SigningProvider> 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));
|
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));
|
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.
|
// Checks the sum amount of all UTXO's.
|
||||||
if (nMinimumSumAmount != MAX_MONEY) {
|
if (nMinimumSumAmount != MAX_MONEY) {
|
||||||
nTotal += wtx.tx->vout[i].nValue;
|
nTotal += output.nValue;
|
||||||
|
|
||||||
if (nTotal >= nMinimumSumAmount) {
|
if (nTotal >= nMinimumSumAmount) {
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in new issue
Block a user