Skip to content

Commit 9b36c9a

Browse files
committed
Merge pull request #1936 from MPOS/pool-bonus-feature
[FEATURE] Added Pool Bonus for Prop and PPLNS
2 parents 914bc6b + d205e53 commit 9b36c9a

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

cronjobs/pplns_payout.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@
181181
}
182182

183183
// Table header for account shares
184-
$strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %20.20s | %20.20s | %20.20s |";
185-
$log->logInfo(sprintf($strLogMask, 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee'));
184+
$strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s |";
185+
$log->logInfo(sprintf($strLogMask, 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee', 'Bonus'));
186186

187187
// Loop through all accounts that have found shares for this round
188188
foreach ($aTotalAccountShares as $key => $aData) {
@@ -201,16 +201,28 @@
201201
// Defaults
202202
$aData['fee' ] = 0;
203203
$aData['donation'] = 0;
204+
$aData['pool_bonus'] = 0;
204205

206+
// Calculate pool fees
205207
if ($config['fees'] > 0 && $aData['no_fees'] == 0)
206208
$aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8);
209+
210+
// Calculate pool bonus if it applies, will be paid from liquid assets!
211+
if ($config['pool_bonus'] > 0) {
212+
if ($config['pool_bonus_type'] == 'block') {
213+
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8);
214+
} else {
215+
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $aData['payout'], 8);
216+
}
217+
}
218+
207219
// Calculate donation amount, fees not included
208220
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
209221

210222
// Verbose output of this users calculations
211223
$log->logInfo(
212224
sprintf($strLogMask, $aData['id'], $aData['username'], $aData['pplns_valid'], $aData['pplns_invalid'],
213-
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8)
225+
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8), number_format($aData['pool_bonus'], 8)
214226
)
215227
);
216228

@@ -225,6 +237,10 @@
225237
if ($aData['donation'] > 0)
226238
if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id']))
227239
$log->logFatal('Failed to insert new Donation transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError() . 'on block ' . $aBlock['id']);
240+
// Add new bonus credit
241+
if ($aData['pool_bonus'] > 0)
242+
if (!$transaction->addTransaction($aData['id'], $aData['pool_bonus'], 'Bonus', $aBlock['id']))
243+
$log->logFatal('Failed to insert new Bonus transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError());
228244
}
229245

230246
// Add full round share statistics

cronjobs/proportional_payout.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040

4141
$count = 0;
4242
// Table header for account shares
43-
$strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %20.20s | %20.20s | %20.20s |";
44-
$log->logInfo(sprintf($strLogMask, 'Block', 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee'));
43+
$strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s |";
44+
$log->logInfo(sprintf($strLogMask, 'Block', 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee', 'Bonus'));
4545
foreach ($aAllBlocks as $iIndex => $aBlock) {
4646
// If we have unaccounted blocks without share_ids, they might not have been inserted yet
4747
if (!$aBlock['share_id']) {
@@ -86,18 +86,30 @@
8686
// Defaults
8787
$aData['fee' ] = 0;
8888
$aData['donation'] = 0;
89+
$aData['pool_bonus'] = 0;
8990
$aData['percentage'] = round(( 100 / $iRoundShares ) * $aData['valid'], 8);
9091
$aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8);
9192

93+
// Calculate pool fees if they apply
9294
if ($config['fees'] > 0 && $aData['no_fees'] == 0)
9395
$aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8);
96+
97+
// Calculate pool bonus if it applies, will be paid from liquid assets!
98+
if ($config['pool_bonus'] > 0) {
99+
if ($config['pool_bonus_type'] == 'block') {
100+
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8);
101+
} else {
102+
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $aData['payout'], 8);
103+
}
104+
}
105+
94106
// Calculate donation amount, fees not included
95107
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
96108

97109
// Verbose output of this users calculations
98110
$log->logInfo(
99111
sprintf($strLogMask, $aBlock['height'], $aData['id'], $aData['username'], $aData['valid'], $aData['invalid'],
100-
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8))
112+
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8), number_format($aData['pool_bonus'], 8))
101113
);
102114

103115
// Update user share statistics
@@ -114,6 +126,10 @@
114126
if ($aData['donation'] > 0)
115127
if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id']))
116128
$log->logFatal('Failed to insert new Donation transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError());
129+
// Add new bonus credit
130+
if ($aData['pool_bonus'] > 0)
131+
if (!$transaction->addTransaction($aData['id'], $aData['pool_bonus'], 'Bonus', $aBlock['id']))
132+
$log->logFatal('Failed to insert new Bonus transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError());
117133
}
118134

119135
// Add block as accounted for into settings table

public/include/config/global.inc.dist.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,14 @@
128128
$config['txfee_manual'] = 0.1;
129129

130130
/**
131-
* Block Bonus
132-
* Bonus in coins of block bonus
131+
* Block & Pool Bonus
132+
* Bonus coins for blockfinder or a pool bonus for everyone
133133
* https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-block-bonus
134+
* https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-pool-bonus
134135
*/
135136
$config['block_bonus'] = 0;
136-
137+
$config['pool_bonus'] = 0;
138+
$config['pool_bonus_type'] = 'payout';
137139

138140
/**
139141
* Payout System

0 commit comments

Comments
 (0)