Skip to content

Commit

Permalink
Fail funded send TXs with more outputs than expected
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar committed Oct 15, 2019
1 parent 0e1621c commit 5a35c60
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/omnicore/wallettxbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,12 @@ int CreateFundedTransaction(
return MP_ENCODING_ERROR;
}

// Maximum number of expected outputs
std::vector<CTxOut>::size_type max_outputs = 2;

// add reference output, if there is one
if (!receiverAddress.empty() && receiverAddress != feeAddress) {
max_outputs = 3;
CScript scriptPubKey = GetScriptForDestination(DecodeDestination(receiverAddress));
vecSend.push_back(std::make_pair(scriptPubKey, OmniGetDustThreshold(scriptPubKey)));
}
Expand Down Expand Up @@ -249,6 +253,13 @@ int CreateFundedTransaction(
strFailReason = "send to self without change";
}

if (wtxNew->get().vout.size() > max_outputs)
{
strFailReason = "more outputs than expected";
PrintToLog("%s: ERROR: more outputs than expected (Max expected %d, actual %d)\n Failed transaction: %s\n",
__func__, max_outputs, wtxNew->get().vout.size(), wtxNew->get().ToString());
}

// to restore the original order of inputs, create a new transaction and add
// inputs and outputs step by step
CMutableTransaction tx;
Expand Down

0 comments on commit 5a35c60

Please sign in to comment.