Skip to content

Commit

Permalink
Updated version. Fixed 0 commission tpos reward distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
durkmurder committed Oct 22, 2020
1 parent 72b3020 commit d781599
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 1)
define(_CLIENT_VERSION_MINOR, 0)
define(_CLIENT_VERSION_REVISION, 25)
define(_CLIENT_VERSION_REVISION, 26)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2020)
Expand Down
32 changes: 20 additions & 12 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,22 +1106,30 @@ void AdjustMasternodePayment(CMutableTransaction &tx, const CTxOut &txoutMastern
{
auto it = std::find(std::begin(tx.vout), std::end(tx.vout), txoutMasternodePayment);

if(it != std::end(tx.vout))
{
if (it != std::end(tx.vout)) {
int mnPaymentOutIndex = std::distance(std::begin(tx.vout), it);
auto masternodePayment = tx.vout[mnPaymentOutIndex].nValue;

int i = tx.vout.size() - 2;
if(tposContract.IsValid()) // here we have 3 outputs, first as stake reward, second as tpos reward, third as MN reward
{
tx.vout[i - 1].nValue -= TPoSUtils::GetOwnerPayment(masternodePayment, tposContract.nOperatorReward); // adjust reward for owner.
// it might be that last vout is masternode, since operator reward was 0
if (tx.vout[i].scriptPubKey == tposContract.scriptMerchantAddress) {
tx.vout[i].nValue -= TPoSUtils::GetOperatorPayment(masternodePayment, tposContract.nOperatorReward); // adjust reward for merchant
if (tposContract.IsValid()) {
// here we have 3 outputs, first as stake reward, second as tpos reward, third as MN reward
auto ownerOutIt = std::find_if(tx.vout.rbegin(),tx.vout.rend(), [&tposContract](const CTxOut &out) {
return out.scriptPubKey == tposContract.scriptTPoSAddress;
});

if (ownerOutIt != tx.vout.rend()) {
ownerOutIt->nValue -= TPoSUtils::GetOwnerPayment(masternodePayment, tposContract.nOperatorReward); // adjust reward for owner.
}
}
else // here we have 2 outputs, first as stake reward, second as MN reward
{

auto merchantOutIt = std::find_if(std::begin(tx.vout), std::end(tx.vout), [&tposContract](const CTxOut &out) {
return out.scriptPubKey == tposContract.scriptMerchantAddress;
});

if (merchantOutIt != std::end(tx.vout)) {
merchantOutIt->nValue -= TPoSUtils::GetOperatorPayment(masternodePayment, tposContract.nOperatorReward); // adjust reward for merchant
}
} else {
// here we have 2 outputs, first as stake reward, second as MN reward
int i = tx.vout.size() - 2;
tx.vout[i].nValue -= masternodePayment; // last vout is mn payment.
}
}
Expand Down

0 comments on commit d781599

Please sign in to comment.