Skip to content

Commit

Permalink
Prevent potential negative out values
Browse files Browse the repository at this point in the history
  • Loading branch information
sombeProject authored Sep 2, 2019
1 parent d2ab86a commit ffbf754
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,20 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe

//subtract mn payment from the stake reward
if (!txNew.vout[1].IsZerocoinMint())
txNew.vout[i - 1].nValue -= masternodePayment;
if (i == 2) {
// Majority of cases; do it quick and move on
txNew.vout[i - 1].nValue -= masternodePayment;
} else if (i > 2) {
// special case, stake is split between (i-1) outputs
unsigned int outputs = i-1;
CAmount mnPaymentSplit = masternodePayment / outputs;
CAmount mnPaymentRemainder = masternodePayment - (mnPaymentSplit * outputs);
for (unsigned int j=1; j<=outputs; j++) {
txNew.vout[j].nValue -= mnPaymentSplit;
}
// in case it's not an even division, take the last bit of dust from the last one
txNew.vout[outputs].nValue -= mnPaymentRemainder;
}
} else {
txNew.vout.resize(2);
txNew.vout[1].scriptPubKey = payee;
Expand Down

0 comments on commit ffbf754

Please sign in to comment.