aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/spend.cpp
diff options
context:
space:
mode:
authorS3RK <1466284+S3RK@users.noreply.github.com>2022-05-18 08:25:04 +0200
committerS3RK <1466284+S3RK@users.noreply.github.com>2022-05-18 08:25:04 +0200
commitc3981e379fa088aa7aa03b2f505342a5b3bc3436 (patch)
treee371d7b5780ea16c1e5b26f110281702468faaf4 /src/wallet/spend.cpp
parentf7a1e676d536115aba649672ba1e68755a1c90dc (diff)
downloadbitcoin-c3981e379fa088aa7aa03b2f505342a5b3bc3436.tar.xz
wallet: do not count wallet utxos as external
Diffstat (limited to 'src/wallet/spend.cpp')
-rw-r--r--src/wallet/spend.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index e5fd7b0eb4..162d06e596 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -1018,14 +1018,28 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet,
coinControl.fAllowOtherInputs = true;
- for (const CTxIn& txin : tx.vin) {
- coinControl.Select(txin.prevout);
- }
-
// Acquire the locks to prevent races to the new locked unspents between the
// CreateTransaction call and LockCoin calls (when lockUnspents is true).
LOCK(wallet.cs_wallet);
+ // Fetch specified UTXOs from the UTXO set to get the scriptPubKeys and values of the outputs being selected
+ // and to match with the given solving_data. Only used for non-wallet outputs.
+ std::map<COutPoint, Coin> coins;
+ for (const CTxIn& txin : tx.vin) {
+ coins[txin.prevout]; // Create empty map entry keyed by prevout.
+ }
+ wallet.chain().findCoins(coins);
+
+ for (const CTxIn& txin : tx.vin) {
+ // if it's not in the wallet and corresponding UTXO is found than select as external output
+ const auto& outPoint = txin.prevout;
+ if (wallet.mapWallet.find(outPoint.hash) == wallet.mapWallet.end() && !coins[outPoint].out.IsNull()) {
+ coinControl.SelectExternal(outPoint, coins[outPoint].out);
+ } else {
+ coinControl.Select(outPoint);
+ }
+ }
+
FeeCalculation fee_calc_out;
std::optional<CreatedTransactionResult> txr = CreateTransaction(wallet, vecSend, nChangePosInOut, error, coinControl, fee_calc_out, false);
if (!txr) return false;