Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,754 Lines • ▼ Show 20 Lines | bool CWallet::SignTransaction(CMutableTransaction &tx) { | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool CWallet::FundTransaction(CMutableTransaction &tx, Amount &nFeeRet, | bool CWallet::FundTransaction(CMutableTransaction &tx, Amount &nFeeRet, | ||||
int &nChangePosInOut, std::string &strFailReason, | int &nChangePosInOut, std::string &strFailReason, | ||||
bool lockUnspents, | bool lockUnspents, | ||||
const std::set<int> &setSubtractFeeFromOutputs, | const std::set<int> &setSubtractFeeFromOutputs, | ||||
CCoinControl coinControl, bool keepReserveKey) { | CCoinControl coinControl) { | ||||
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, | CRecipient recipient = {txOut.scriptPubKey, txOut.nValue, | ||||
setSubtractFeeFromOutputs.count(idx) == 1}; | setSubtractFeeFromOutputs.count(idx) == 1}; | ||||
vecSend.push_back(recipient); | vecSend.push_back(recipient); | ||||
Show All 11 Lines | if (!CreateTransaction(vecSend, tx_new, reservekey, nFeeRet, | ||||
nChangePosInOut, strFailReason, coinControl, | nChangePosInOut, strFailReason, coinControl, | ||||
false)) { | false)) { | ||||
return false; | return false; | ||||
} | } | ||||
if (nChangePosInOut != -1) { | if (nChangePosInOut != -1) { | ||||
tx.vout.insert(tx.vout.begin() + nChangePosInOut, | tx.vout.insert(tx.vout.begin() + nChangePosInOut, | ||||
tx_new->vout[nChangePosInOut]); | tx_new->vout[nChangePosInOut]); | ||||
// we dont have the normal Create/Commit cycle, and dont want to risk | |||||
// reusing change, so just remove the key from the keypool here. | |||||
reservekey.KeepKey(); | |||||
} | } | ||||
// Copy output sizes from new transaction; they may have had the fee | // Copy output sizes from new transaction; they may have had the fee | ||||
// subtracted from them. | // subtracted from them. | ||||
for (size_t idx = 0; idx < tx.vout.size(); idx++) { | for (size_t idx = 0; idx < tx.vout.size(); idx++) { | ||||
tx.vout[idx].nValue = tx_new->vout[idx].nValue; | tx.vout[idx].nValue = tx_new->vout[idx].nValue; | ||||
} | } | ||||
// Add new txins (keeping original txin scriptSig/order) | // Add new txins (keeping original txin scriptSig/order) | ||||
for (const CTxIn &txin : tx_new->vin) { | for (const CTxIn &txin : tx_new->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); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Optionally keep the change output key. | |||||
if (keepReserveKey) { | |||||
reservekey.KeepKey(); | |||||
} | |||||
return true; | return true; | ||||
} | } | ||||
bool CWallet::CreateTransaction(const std::vector<CRecipient> &vecSend, | bool CWallet::CreateTransaction(const std::vector<CRecipient> &vecSend, | ||||
CTransactionRef &tx, CReserveKey &reservekey, | CTransactionRef &tx, CReserveKey &reservekey, | ||||
Amount &nFeeRet, int &nChangePosInOut, | Amount &nFeeRet, int &nChangePosInOut, | ||||
std::string &strFailReason, | std::string &strFailReason, | ||||
const CCoinControl &coinControl, bool sign) { | const CCoinControl &coinControl, bool sign) { | ||||
▲ Show 20 Lines • Show All 1,644 Lines • Show Last 20 Lines |