mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-11 01:26:10 +01:00
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.
This commit is contained in:
parent
f2d00bfe1a
commit
a537d7aaa0
2 changed files with 9 additions and 5 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -408,7 +408,7 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
inputs = [ {'txid' : "1c7f966dab21119bac53213a2bc7532bff1fa844c124fd750a7d0b1332440bd1", 'vout' : 0} ] #invalid vin!
|
||||
outputs = { self.nodes[0].getnewaddress() : 1.0}
|
||||
rawtx = self.nodes[2].createrawtransaction(inputs, outputs)
|
||||
assert_raises_rpc_error(-4, "Insufficient funds", self.nodes[2].fundrawtransaction, rawtx)
|
||||
assert_raises_rpc_error(-4, "Unable to find UTXO for external input", self.nodes[2].fundrawtransaction, rawtx)
|
||||
|
||||
def test_fee_p2pkh(self):
|
||||
"""Compare fee of a standard pubkeyhash transaction."""
|
||||
|
|
Loading…
Add table
Reference in a new issue