Skip to content

Commit 5f035ef

Browse files
committed
wallet: do not count wallet utxos as external
1 parent 9015d11 commit 5f035ef

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/wallet/rpc/spend.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -564,19 +564,6 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
564564
setSubtractFeeFromOutputs.insert(pos);
565565
}
566566

567-
// Fetch specified UTXOs from the UTXO set to get the scriptPubKeys and values of the outputs being selected
568-
// and to match with the given solving_data. Only used for non-wallet outputs.
569-
std::map<COutPoint, Coin> coins;
570-
for (const CTxIn& txin : tx.vin) {
571-
coins[txin.prevout]; // Create empty map entry keyed by prevout.
572-
}
573-
wallet.chain().findCoins(coins);
574-
for (const auto& coin : coins) {
575-
if (!coin.second.out.IsNull()) {
576-
coinControl.SelectExternal(coin.first, coin.second.out);
577-
}
578-
}
579-
580567
bilingual_str error;
581568

582569
if (!FundTransaction(wallet, tx, fee_out, change_position, error, lockUnspents, setSubtractFeeFromOutputs, coinControl)) {

src/wallet/spend.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,14 +992,28 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
992992

993993
coinControl.fAllowOtherInputs = true;
994994

995-
for (const CTxIn& txin : tx.vin) {
996-
coinControl.Select(txin.prevout);
997-
}
998-
999995
// Acquire the locks to prevent races to the new locked unspents between the
1000996
// CreateTransaction call and LockCoin calls (when lockUnspents is true).
1001997
LOCK(wallet.cs_wallet);
1002998

999+
// Fetch specified UTXOs from the UTXO set to get the scriptPubKeys and values of the outputs being selected
1000+
// and to match with the given solving_data. Only used for non-wallet outputs.
1001+
std::map<COutPoint, Coin> coins;
1002+
for (const CTxIn& txin : tx.vin) {
1003+
coins[txin.prevout]; // Create empty map entry keyed by prevout.
1004+
}
1005+
wallet.chain().findCoins(coins);
1006+
1007+
for (const CTxIn& txin : tx.vin) {
1008+
// if it's not in the wallet and corresponding UTXO is found than select as external output
1009+
const auto& outPoint = txin.prevout;
1010+
if (wallet.mapWallet.find(outPoint.hash) == wallet.mapWallet.end() && !coins[outPoint].out.IsNull()) {
1011+
coinControl.SelectExternal(outPoint, coins[outPoint].out);
1012+
} else {
1013+
coinControl.Select(outPoint);
1014+
}
1015+
}
1016+
10031017
CTransactionRef tx_new;
10041018
FeeCalculation fee_calc_out;
10051019
if (!CreateTransaction(wallet, vecSend, tx_new, nFeeRet, nChangePosInOut, error, coinControl, fee_calc_out, false)) {

0 commit comments

Comments
 (0)