mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
wallet: AvailableCoins, don't call 'wtx.tx->vout[i]' multiple times
This commit is contained in:
parent
4ce235ef8f
commit
9472ca0a65
1 changed files with 12 additions and 9 deletions
|
@ -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<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));
|
||||
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;
|
||||
|
|
Loading…
Add table
Reference in a new issue