aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
diff options
context:
space:
mode:
authorAlex Morcos <morcos@chaincode.com>2017-01-05 09:10:08 -0500
committerAlex Morcos <morcos@chaincode.com>2017-01-06 10:12:05 -0500
commit42f5ce40931402aaa395ef2959deb64e9a9fff02 (patch)
tree650bad83761a48cafdeed51a047fb3a63b559a3c /src/wallet/wallet.cpp
parentf646275b90b1de93bc62b4c4d045d75ac0b96eee (diff)
downloadbitcoin-42f5ce40931402aaa395ef2959deb64e9a9fff02.tar.xz
Try to reduce change output to make needed fee in CreateTransaction
Once we've picked coins and dummy-signed the transaction to calculate fee, if we don't have sufficient fee, then try to meet the fee by reducing change before resorting to picking new coins.
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r--src/wallet/wallet.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index ff7a03bc55..bdf6d3c7a6 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2537,6 +2537,18 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
if (nFeeRet >= nFeeNeeded)
break; // Done, enough fee included.
+ // Try to reduce change to include necessary fee
+ if (nChangePosInOut != -1 && nSubtractFeeFromAmount == 0) {
+ CAmount additionalFeeNeeded = nFeeNeeded - nFeeRet;
+ vector<CTxOut>::iterator change_position = txNew.vout.begin()+nChangePosInOut;
+ // Only reduce change if remaining amount is still a large enough output.
+ if (change_position->nValue >= MIN_FINAL_CHANGE + additionalFeeNeeded) {
+ change_position->nValue -= additionalFeeNeeded;
+ nFeeRet += additionalFeeNeeded;
+ break; // Done, able to increase fee from change
+ }
+ }
+
// Include more fee and try again.
nFeeRet = nFeeNeeded;
continue;