[wallet] Tidy up CWallet::FundTransaction
This commit is contained in:
parent
8ab6c0b09e
commit
95d4450a41
|
@ -2592,9 +2592,8 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
|
||||||
{
|
{
|
||||||
std::vector<CRecipient> vecSend;
|
std::vector<CRecipient> vecSend;
|
||||||
|
|
||||||
// Turn the txout set into a CRecipient vector
|
// Turn the txout set into a CRecipient vector.
|
||||||
for (size_t idx = 0; idx < tx.vout.size(); idx++)
|
for (size_t idx = 0; idx < tx.vout.size(); idx++) {
|
||||||
{
|
|
||||||
const CTxOut& txOut = tx.vout[idx];
|
const CTxOut& txOut = tx.vout[idx];
|
||||||
CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1};
|
CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, setSubtractFeeFromOutputs.count(idx) == 1};
|
||||||
vecSend.push_back(recipient);
|
vecSend.push_back(recipient);
|
||||||
|
@ -2602,8 +2601,9 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
|
||||||
|
|
||||||
coinControl.fAllowOtherInputs = true;
|
coinControl.fAllowOtherInputs = true;
|
||||||
|
|
||||||
for (const CTxIn& txin : tx.vin)
|
for (const CTxIn& txin : tx.vin) {
|
||||||
coinControl.Select(txin.prevout);
|
coinControl.Select(txin.prevout);
|
||||||
|
}
|
||||||
|
|
||||||
CReserveKey reservekey(this);
|
CReserveKey reservekey(this);
|
||||||
CWalletTx wtx;
|
CWalletTx wtx;
|
||||||
|
@ -2613,31 +2613,29 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
|
||||||
|
|
||||||
if (nChangePosInOut != -1) {
|
if (nChangePosInOut != -1) {
|
||||||
tx.vout.insert(tx.vout.begin() + nChangePosInOut, wtx.tx->vout[nChangePosInOut]);
|
tx.vout.insert(tx.vout.begin() + nChangePosInOut, wtx.tx->vout[nChangePosInOut]);
|
||||||
// we don't have the normal Create/Commit cycle, and don't want to risk reusing change,
|
// We don't have the normal Create/Commit cycle, and don't want to risk
|
||||||
// so just remove the key from the keypool here.
|
// reusing change, so just remove the key from the keypool here.
|
||||||
reservekey.KeepKey();
|
reservekey.KeepKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy output sizes from new transaction; they may have had the fee subtracted from them
|
// Copy output sizes from new transaction; they may have had the fee
|
||||||
for (unsigned int idx = 0; idx < tx.vout.size(); idx++)
|
// subtracted from them.
|
||||||
|
for (unsigned int idx = 0; idx < tx.vout.size(); idx++) {
|
||||||
tx.vout[idx].nValue = wtx.tx->vout[idx].nValue;
|
tx.vout[idx].nValue = wtx.tx->vout[idx].nValue;
|
||||||
|
}
|
||||||
|
|
||||||
// Add new txins (keeping original txin scriptSig/order)
|
// Add new txins while keeping original txin scriptSig/order.
|
||||||
for (const CTxIn& txin : wtx.tx->vin)
|
for (const CTxIn& txin : wtx.tx->vin) {
|
||||||
{
|
if (!coinControl.IsSelected(txin.prevout)) {
|
||||||
if (!coinControl.IsSelected(txin.prevout))
|
|
||||||
{
|
|
||||||
tx.vin.push_back(txin);
|
tx.vin.push_back(txin);
|
||||||
|
|
||||||
if (lockUnspents)
|
if (lockUnspents) {
|
||||||
{
|
|
||||||
LOCK2(cs_main, cs_wallet);
|
LOCK2(cs_main, cs_wallet);
|
||||||
LockCoin(txin.prevout);
|
LockCoin(txin.prevout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue