Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 2,949 Lines • ▼ Show 20 Lines | assert(txNew.nLockTime < LOCKTIME_THRESHOLD); | ||||
// Fill in dummy signatures for fee calculation. | // Fill in dummy signatures for fee calculation. | ||||
if (!DummySignTx(txNew, setCoins)) { | if (!DummySignTx(txNew, setCoins)) { | ||||
strFailReason = _("Signing transaction failed"); | strFailReason = _("Signing transaction failed"); | ||||
return false; | return false; | ||||
} | } | ||||
CTransaction txNewConst(txNew); | CTransaction txNewConst(txNew); | ||||
unsigned int nBytes = txNewConst.GetTotalSize(); | unsigned int nBytes = txNewConst.GetTotalSize(); | ||||
// Note: The relaying code has been changed to charge upfront for | |||||
// the minimum required bytes to spend a UTXO. This means that | |||||
jasonbcox: duplicate space | |||||
// we need to calculate possible fees based that size. | |||||
size_t feeBytes = txNewConst.GetBillableSize(); | |||||
dPriority = txNewConst.ComputePriority(dPriority, nBytes); | dPriority = txNewConst.ComputePriority(dPriority, nBytes); | ||||
// Remove scriptSigs to eliminate the fee calculation dummy | // Remove scriptSigs to eliminate the fee calculation dummy | ||||
// signatures. | // signatures. | ||||
for (auto &vin : txNew.vin) { | for (auto &vin : txNew.vin) { | ||||
vin.scriptSig = CScript(); | vin.scriptSig = CScript(); | ||||
} | } | ||||
// Allow to override the default confirmation target over the | // Allow to override the default confirmation target over the | ||||
// CoinControl instance. | // CoinControl instance. | ||||
int currentConfirmationTarget = nTxConfirmTarget; | int currentConfirmationTarget = nTxConfirmTarget; | ||||
if (coinControl && coinControl->nConfirmTarget > 0) { | if (coinControl && coinControl->nConfirmTarget > 0) { | ||||
currentConfirmationTarget = coinControl->nConfirmTarget; | currentConfirmationTarget = coinControl->nConfirmTarget; | ||||
} | } | ||||
Amount nFeeNeeded = | Amount nFeeNeeded = | ||||
GetMinimumFee(nBytes, currentConfirmationTarget, mempool); | GetMinimumFee(feeBytes, currentConfirmationTarget, mempool); | ||||
if (coinControl && nFeeNeeded > Amount::zero() && | if (coinControl && nFeeNeeded > Amount::zero() && | ||||
coinControl->nMinimumTotalFee > nFeeNeeded) { | coinControl->nMinimumTotalFee > nFeeNeeded) { | ||||
nFeeNeeded = coinControl->nMinimumTotalFee; | nFeeNeeded = coinControl->nMinimumTotalFee; | ||||
} | } | ||||
if (coinControl && coinControl->fOverrideFeeRate) { | if (coinControl && coinControl->fOverrideFeeRate) { | ||||
nFeeNeeded = coinControl->nFeeRate.GetFeeCeiling(nBytes); | nFeeNeeded = coinControl->nFeeRate.GetFeeCeiling(feeBytes); | ||||
} | } | ||||
// If we made it here and we aren't even able to meet the relay fee | // If we made it here and we aren't even able to meet the relay fee | ||||
// on the next pass, give up because we must be at the maximum | // on the next pass, give up because we must be at the maximum | ||||
// allowed fee. | // allowed fee. | ||||
Amount minFee = GetConfig().GetMinFeePerKB().GetFeeCeiling(nBytes); | Amount minFee = GetConfig().GetMinFeePerKB().GetFee(feeBytes); | ||||
if (nFeeNeeded < minFee) { | if (nFeeNeeded < minFee) { | ||||
strFailReason = _("Transaction too large for fee policy"); | strFailReason = _("Transaction too large for fee policy"); | ||||
return false; | return false; | ||||
} | } | ||||
if (nFeeRet >= nFeeNeeded) { | if (nFeeRet >= nFeeNeeded) { | ||||
// Reduce fee to only the needed amount if we have change output | // Reduce fee to only the needed amount if we have change output | ||||
// to increase. This prevents potential overpayment in fees if | // to increase. This prevents potential overpayment in fees if | ||||
Show All 30 Lines | assert(txNew.nLockTime < LOCKTIME_THRESHOLD); | ||||
nFeeRet += additionalFeeNeeded; | nFeeRet += additionalFeeNeeded; | ||||
// Done, able to increase fee from change. | // Done, able to increase fee from change. | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// Include more fee and try again. | // Include more fee and try again. | ||||
nFeeRet = nFeeNeeded; | nFeeRet = nFeeNeeded; | ||||
continue; | continue; | ||||
} | } | ||||
if (sign) { | if (sign) { | ||||
SigHashType sigHashType = SigHashType().withForkId(); | SigHashType sigHashType = SigHashType().withForkId(); | ||||
CTransaction txNewConst(txNew); | CTransaction txNewConst(txNew); | ||||
int nIn = 0; | int nIn = 0; | ||||
▲ Show 20 Lines • Show All 1,539 Lines • Show Last 20 Lines |
duplicate space