diff options
author | Andrew Chow <achow101-github@achow101.com> | 2022-07-22 15:30:10 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2022-08-18 11:00:12 -0400 |
commit | a537d7aaa069bc216aeab381bbc4d312b5ffedf1 (patch) | |
tree | 72a2e800a43e17046810f62bffcb9b16d2f2afea /src/wallet/spend.cpp | |
parent | f2d00bfe1a32a11c0d88e8c1d3bae6a6b01db15e (diff) |
wallet: SelectExternal actually external inputs
If an external input's utxo was created by a transaction that the wallet
knows about, then it would not be selected using SelectExternal. This
results in either funding failure or incorrect weight calculation.
Diffstat (limited to 'src/wallet/spend.cpp')
-rw-r--r-- | src/wallet/spend.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index d6362c1f14..bffb665fa8 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -1127,12 +1127,16 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet, 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 { + if (wallet.IsMine(outPoint)) { + // The input was found in the wallet, so select as internal coinControl.Select(outPoint); + } else if (coins[outPoint].out.IsNull()) { + error = _("Unable to find UTXO for external input"); + return false; + } else { + // The input was not in the wallet, but is in the UTXO set, so select as external + coinControl.SelectExternal(outPoint, coins[outPoint].out); } } |