Skip to content

Commit b0c837c

Browse files
committed
Don't create two similar outputs, when funding transactions
When specifying a similar destination for the recipient of the transaction and source to pay the fees with, the builder would create a transaction with two similar outputs. This is combined into one with this change.
1 parent c0738a9 commit b0c837c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/omnicore/wallettxbuilder.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ int CreateFundedTransaction(
203203
}
204204

205205
// add reference output, if there is one
206-
if (!receiverAddress.empty()) {
206+
if (!receiverAddress.empty() && receiverAddress != feeAddress) {
207207
CScript scriptPubKey = GetScriptForDestination(CBitcoinAddress(receiverAddress).Get());
208208
vecSend.push_back(std::make_pair(scriptPubKey, GetDustThreshold(scriptPubKey)));
209209
}
@@ -232,7 +232,7 @@ int CreateFundedTransaction(
232232
PrintToLog("%s: ERROR: sender %s has no coins\n", __func__, senderAddress);
233233
return MP_INPUTS_INVALID;
234234
}
235-
235+
236236
// prepare sources for fees
237237
std::set<CTxDestination> feeSources;
238238
feeSources.insert(CBitcoinAddress(feeAddress).Get());
@@ -244,6 +244,11 @@ int CreateFundedTransaction(
244244

245245
fSuccess = pwalletMain->CreateTransaction(vecRecipients, wtxNew, reserveKey, nFeeRequired, nChangePosRet, strFailReason, &coinControl, false);
246246

247+
if (fSuccess && nChangePosRet == -1 && receiverAddress == feeAddress) {
248+
fSuccess = false;
249+
strFailReason = "send to self without change";
250+
}
251+
247252
// to restore the original order of inputs, create a new transaction and add
248253
// inputs and outputs step by step
249254
CMutableTransaction tx;

0 commit comments

Comments
 (0)