Skip to content

Commit c3981e3

Browse files
committed
wallet: do not count wallet utxos as external
1 parent f7a1e67 commit c3981e3

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
@@ -699,19 +699,6 @@ void FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& fee_out,
699699
setSubtractFeeFromOutputs.insert(pos);
700700
}
701701

702-
// Fetch specified UTXOs from the UTXO set to get the scriptPubKeys and values of the outputs being selected
703-
// and to match with the given solving_data. Only used for non-wallet outputs.
704-
std::map<COutPoint, Coin> coins;
705-
for (const CTxIn& txin : tx.vin) {
706-
coins[txin.prevout]; // Create empty map entry keyed by prevout.
707-
}
708-
wallet.chain().findCoins(coins);
709-
for (const auto& coin : coins) {
710-
if (!coin.second.out.IsNull()) {
711-
coinControl.SelectExternal(coin.first, coin.second.out);
712-
}
713-
}
714-
715702
bilingual_str error;
716703

717704
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
@@ -1018,14 +1018,28 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
10181018

10191019
coinControl.fAllowOtherInputs = true;
10201020

1021-
for (const CTxIn& txin : tx.vin) {
1022-
coinControl.Select(txin.prevout);
1023-
}
1024-
10251021
// Acquire the locks to prevent races to the new locked unspents between the
10261022
// CreateTransaction call and LockCoin calls (when lockUnspents is true).
10271023
LOCK(wallet.cs_wallet);
10281024

1025+
// Fetch specified UTXOs from the UTXO set to get the scriptPubKeys and values of the outputs being selected
1026+
// and to match with the given solving_data. Only used for non-wallet outputs.
1027+
std::map<COutPoint, Coin> coins;
1028+
for (const CTxIn& txin : tx.vin) {
1029+
coins[txin.prevout]; // Create empty map entry keyed by prevout.
1030+
}
1031+
wallet.chain().findCoins(coins);
1032+
1033+
for (const CTxIn& txin : tx.vin) {
1034+
// if it's not in the wallet and corresponding UTXO is found than select as external output
1035+
const auto& outPoint = txin.prevout;
1036+
if (wallet.mapWallet.find(outPoint.hash) == wallet.mapWallet.end() && !coins[outPoint].out.IsNull()) {
1037+
coinControl.SelectExternal(outPoint, coins[outPoint].out);
1038+
} else {
1039+
coinControl.Select(outPoint);
1040+
}
1041+
}
1042+
10291043
FeeCalculation fee_calc_out;
10301044
std::optional<CreatedTransactionResult> txr = CreateTransaction(wallet, vecSend, nChangePosInOut, error, coinControl, fee_calc_out, false);
10311045
if (!txr) return false;

0 commit comments

Comments
 (0)