Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 11 additions & 2 deletions src/stakeinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,17 @@ bool CPivStake::CreateTxOuts(CWallet* pwallet, std::vector<CTxOut>& vout, CAmoun
vout.emplace_back(CTxOut(0, scriptPubKey));

// Calculate if we need to split the output
if (nTotal / 2 > (CAmount)(pwallet->nStakeSplitThreshold * COIN))
vout.emplace_back(CTxOut(0, scriptPubKey));
int nSplit = nTotal / (static_cast<CAmount>(pwallet->nStakeSplitThreshold * COIN));
if (nSplit > 1) {
// if nTotal is twice or more of the threshold; create more outputs
int txSizeMax = MAX_STANDARD_TX_SIZE >> 11; // limit splits to <10% of the max TX size (/2048)
if (nSplit > txSizeMax)
nSplit = txSizeMax;
for (int i = nSplit; i > 1; i--) {
LogPrintf("%s: StakeSplit: nTotal = %d; adding output %d of %d\n", __func__, nTotal, (nSplit-i)+2, nSplit);
vout.emplace_back(CTxOut(0, scriptPubKey));
}
}

return true;
}
Expand Down
18 changes: 13 additions & 5 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2425,11 +2425,19 @@ bool CWallet::CreateCoinStake(
CAmount nMinFee = 0;
if (!stakeInput->IsZPIV()) {
// Set output amount
if (txNew.vout.size() == 3) {
txNew.vout[1].nValue = ((nCredit - nMinFee) / 2 / CENT) * CENT;
txNew.vout[2].nValue = nCredit - nMinFee - txNew.vout[1].nValue;
} else
txNew.vout[1].nValue = nCredit - nMinFee;
unsigned int outputs = txNew.vout.size() - 1;
CAmount nRemaining = nCredit - nMinFee;
if (outputs > 1) {
// Split the stake across the outputs
CAmount nShare = nRemaining / outputs;
for (int i = 1; i < outputs; i++) {
// loop through all but the last one.
txNew.vout[i].nValue = nShare;
nRemaining -= nShare;
}
}
// put the remaining on the last output (which all into the first if only one output)
txNew.vout[outputs].nValue += nRemaining;
}

// Limit size
Expand Down