Merge branch 'development' into bootstrap

This commit is contained in:
Sebastian Grewe 2014-03-17 15:53:53 +01:00
commit e863ef3a0a
8 changed files with 59 additions and 20 deletions

View File

@ -181,8 +181,8 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
} }
// Table header for account shares // Table header for account shares
$strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %20.20s | %20.20s | %20.20s |"; $strLogMask = "| %5.5s | %-15.15s | %15.15s | %15.15s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s |";
$log->logInfo(sprintf($strLogMask, 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee')); $log->logInfo(sprintf($strLogMask, 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee', 'Bonus'));
// Loop through all accounts that have found shares for this round // Loop through all accounts that have found shares for this round
foreach ($aTotalAccountShares as $key => $aData) { foreach ($aTotalAccountShares as $key => $aData) {
@ -201,16 +201,28 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
// Defaults // Defaults
$aData['fee' ] = 0; $aData['fee' ] = 0;
$aData['donation'] = 0; $aData['donation'] = 0;
$aData['pool_bonus'] = 0;
// Calculate pool fees
if ($config['fees'] > 0 && $aData['no_fees'] == 0) if ($config['fees'] > 0 && $aData['no_fees'] == 0)
$aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8); $aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8);
// Calculate pool bonus if it applies, will be paid from liquid assets!
if ($config['pool_bonus'] > 0) {
if ($config['pool_bonus_type'] == 'block') {
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8);
} else {
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $aData['payout'], 8);
}
}
// Calculate donation amount, fees not included // Calculate donation amount, fees not included
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8); $aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
// Verbose output of this users calculations // Verbose output of this users calculations
$log->logInfo( $log->logInfo(
sprintf($strLogMask, $aData['id'], $aData['username'], $aData['pplns_valid'], $aData['pplns_invalid'], sprintf($strLogMask, $aData['id'], $aData['username'], $aData['pplns_valid'], $aData['pplns_invalid'],
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8) 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)
) )
); );
@ -225,6 +237,10 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
if ($aData['donation'] > 0) if ($aData['donation'] > 0)
if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id'])) if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id']))
$log->logFatal('Failed to insert new Donation transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError() . 'on block ' . $aBlock['id']); $log->logFatal('Failed to insert new Donation transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError() . 'on block ' . $aBlock['id']);
// Add new bonus credit
if ($aData['pool_bonus'] > 0)
if (!$transaction->addTransaction($aData['id'], $aData['pool_bonus'], 'Bonus', $aBlock['id']))
$log->logFatal('Failed to insert new Bonus transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError());
} }
// Add full round share statistics // Add full round share statistics

View File

@ -40,8 +40,8 @@ if (empty($aAllBlocks)) {
$count = 0; $count = 0;
// Table header for account shares // Table header for account shares
$strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %20.20s | %20.20s | %20.20s |"; $strLogMask = "| %10.10s | %-5.5s | %15.15s | %15.15s | %12.12s | %12.12s | %15.15s | %15.15s | %15.15s | %15.15s |";
$log->logInfo(sprintf($strLogMask, 'Block', 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee')); $log->logInfo(sprintf($strLogMask, 'Block', 'ID', 'Username', 'Valid', 'Invalid', 'Percentage', 'Payout', 'Donation', 'Fee', 'Bonus'));
foreach ($aAllBlocks as $iIndex => $aBlock) { foreach ($aAllBlocks as $iIndex => $aBlock) {
// If we have unaccounted blocks without share_ids, they might not have been inserted yet // If we have unaccounted blocks without share_ids, they might not have been inserted yet
if (!$aBlock['share_id']) { if (!$aBlock['share_id']) {
@ -86,18 +86,30 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
// Defaults // Defaults
$aData['fee' ] = 0; $aData['fee' ] = 0;
$aData['donation'] = 0; $aData['donation'] = 0;
$aData['pool_bonus'] = 0;
$aData['percentage'] = round(( 100 / $iRoundShares ) * $aData['valid'], 8); $aData['percentage'] = round(( 100 / $iRoundShares ) * $aData['valid'], 8);
$aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8); $aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8);
// Calculate pool fees if they apply
if ($config['fees'] > 0 && $aData['no_fees'] == 0) if ($config['fees'] > 0 && $aData['no_fees'] == 0)
$aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8); $aData['fee'] = round($config['fees'] / 100 * $aData['payout'], 8);
// Calculate pool bonus if it applies, will be paid from liquid assets!
if ($config['pool_bonus'] > 0) {
if ($config['pool_bonus_type'] == 'block') {
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $dReward, 8);
} else {
$aData['pool_bonus'] = round(( $config['pool_bonus'] / 100 ) * $aData['payout'], 8);
}
}
// Calculate donation amount, fees not included // Calculate donation amount, fees not included
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8); $aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 8);
// Verbose output of this users calculations // Verbose output of this users calculations
$log->logInfo( $log->logInfo(
sprintf($strLogMask, $aBlock['height'], $aData['id'], $aData['username'], $aData['valid'], $aData['invalid'], sprintf($strLogMask, $aBlock['height'], $aData['id'], $aData['username'], $aData['valid'], $aData['invalid'],
number_format($aData['percentage'], 8), number_format($aData['payout'], 8), number_format($aData['donation'], 8), number_format($aData['fee'], 8)) 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))
); );
// Update user share statistics // Update user share statistics
@ -114,6 +126,10 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
if ($aData['donation'] > 0) if ($aData['donation'] > 0)
if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id'])) if (!$transaction->addTransaction($aData['id'], $aData['donation'], 'Donation', $aBlock['id']))
$log->logFatal('Failed to insert new Donation transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError()); $log->logFatal('Failed to insert new Donation transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError());
// Add new bonus credit
if ($aData['pool_bonus'] > 0)
if (!$transaction->addTransaction($aData['id'], $aData['pool_bonus'], 'Bonus', $aBlock['id']))
$log->logFatal('Failed to insert new Bonus transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError());
} }
// Add block as accounted for into settings table // Add block as accounted for into settings table

View File

@ -462,14 +462,14 @@ class Statistics extends Base {
id, id,
IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty, IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty,
username username
FROM shares FROM " . $this->share->getTableName() . "
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' WHERE time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y'
UNION UNION
SELECT SELECT
share_id, share_id,
IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty, IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty,
username username
FROM shares_archive FROM " . $this->share->getArchiveTableName() . "
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y' WHERE time > DATE_SUB(now(), INTERVAL ? SECOND) AND our_result = 'Y'
) AS t1 ) AS t1
LEFT JOIN " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->user->getTableName() . " AS a
@ -533,7 +533,7 @@ class Statistics extends Base {
SELECT SELECT
id, our_result, IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty id, our_result, IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty
FROM FROM
shares " . $this->share->getTableName() . "
WHERE username LIKE ? WHERE username LIKE ?
AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND time > DATE_SUB(now(), INTERVAL ? SECOND)
AND our_result = 'Y' AND our_result = 'Y'
@ -541,7 +541,7 @@ class Statistics extends Base {
SELECT SELECT
share_id, our_result, IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty share_id, our_result, IF(difficulty = 0, POW(2, (" . $this->config['difficulty'] . " - 16)), difficulty) AS difficulty
FROM FROM
shares_archive " . $this->share->getArchiveTableName() . "
WHERE username LIKE ? WHERE username LIKE ?
AND time > DATE_SUB(now(), INTERVAL ? SECOND) AND time > DATE_SUB(now(), INTERVAL ? SECOND)
AND our_result = 'Y' AND our_result = 'Y'

View File

@ -55,6 +55,8 @@ class Tools extends Base {
return 'btce'; return 'btce';
} else if (preg_match('/cryptsy.com/', $url)) { } else if (preg_match('/cryptsy.com/', $url)) {
return 'cryptsy'; return 'cryptsy';
} else if (preg_match('/cryptorush.in/', $url)) {
return 'cryptorush';
} }
$this->setErrorMessage("API URL unknown"); $this->setErrorMessage("API URL unknown");
return false; return false;
@ -84,6 +86,9 @@ class Tools extends Base {
case 'cryptsy': case 'cryptsy':
return @$aData['return']['markets'][$strCurrency]['lasttradeprice']; return @$aData['return']['markets'][$strCurrency]['lasttradeprice'];
break; break;
case 'cryptorush':
return @$aData["$strCurrency/" . $this->config['price']['target']]['last_trade'];
break;
} }
} else { } else {
$this->setErrorMessage("Got an invalid response from ticker API"); $this->setErrorMessage("Got an invalid response from ticker API");

View File

@ -70,8 +70,8 @@ class Transaction extends Base {
$sql = " $sql = "
SELECT SELECT
SUM(t.amount) AS total, t.type AS type SUM(t.amount) AS total, t.type AS type
FROM transactions AS t FROM $this->table AS t
LEFT OUTER JOIN blocks AS b LEFT OUTER JOIN " . $this->block->getTableName() . " AS b
ON b.id = t.block_id ON b.id = t.block_id
WHERE ( b.confirmations > 0 OR b.id IS NULL )"; WHERE ( b.confirmations > 0 OR b.id IS NULL )";
if (!empty($account_id)) { if (!empty($account_id)) {
@ -265,7 +265,7 @@ class Transaction extends Base {
FROM $this->table AS t FROM $this->table AS t
LEFT JOIN " . $this->user->getTableName() . " AS a LEFT JOIN " . $this->user->getTableName() . " AS a
ON t.account_id = a.id ON t.account_id = a.id
LEFT JOIN blocks AS b LEFT JOIN " . $this->block->getTableName() . " AS b
ON t.block_id = b.id ON t.block_id = b.id
WHERE WHERE
( (
@ -360,9 +360,9 @@ class Transaction extends Base {
), 0 ), 0
) AS confirmed ) AS confirmed
FROM $this->table AS t FROM $this->table AS t
LEFT JOIN blocks AS b LEFT JOIN " . $this->block->getTableName() . " AS b
ON t.block_id = b.id ON t.block_id = b.id
LEFT JOIN accounts AS a LEFT JOIN " . $this->user->getTableName() . " AS a
ON t.account_id = a.id ON t.account_id = a.id
WHERE t.archived = 0 AND a.ap_threshold > 0 AND a.coin_address IS NOT NULL AND a.coin_address != '' WHERE t.archived = 0 AND a.ap_threshold > 0 AND a.coin_address IS NOT NULL AND a.coin_address != ''
GROUP BY t.account_id GROUP BY t.account_id

View File

@ -136,12 +136,14 @@ $config['txfee_auto'] = 0.1;
$config['txfee_manual'] = 0.1; $config['txfee_manual'] = 0.1;
/** /**
* Block Bonus * Block & Pool Bonus
* Bonus in coins of block bonus * Bonus coins for blockfinder or a pool bonus for everyone
* https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-block-bonus * https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-block-bonus
* https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-pool-bonus
*/ */
$config['block_bonus'] = 0; $config['block_bonus'] = 0;
$config['pool_bonus'] = 0;
$config['pool_bonus_type'] = 'payout';
/** /**
* Payout System * Payout System

View File

@ -18,7 +18,7 @@
<td>{if $PPLNSROUNDSHARES[contrib].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$PPLNSROUNDSHARES[contrib].username|default:"unknown"|escape}{/if}</td> <td>{if $PPLNSROUNDSHARES[contrib].is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$PPLNSROUNDSHARES[contrib].username|default:"unknown"|escape}{/if}</td>
<td align="right">{$PPLNSROUNDSHARES[contrib].pplns_valid|number_format}</td> <td align="right">{$PPLNSROUNDSHARES[contrib].pplns_valid|number_format}</td>
<td align="right">{$PPLNSROUNDSHARES[contrib].pplns_invalid|number_format}</td> <td align="right">{$PPLNSROUNDSHARES[contrib].pplns_invalid|number_format}</td>
<td align="right" style="padding-right: 25px;">{if $PPLNSROUNDSHARES[contrib].pplns_invalid > 0 && $PPLNSROUNDSHARES[contrib].pplns_valid > 0}{($PPLNSROUNDSHARES[contrib].pplns_invalid / $PPLNSROUNDSHARES[contrib].pplns_valid * 100)|number_format:"2"|default:"0"}{else}0.00{/if}</td> <td align="right" style="padding-right: 25px;">{if $PPLNSROUNDSHARES[contrib].pplns_invalid > 0 && $PPLNSROUNDSHARES[contrib].pplns_valid > 0}{(($PPLNSROUNDSHARES[contrib].pplns_invalid / ($PPLNSROUNDSHARES[contrib].pplns_valid + $PPLNSROUNDSHARES[contrib].pplns_invalid)) * 100)|number_format:"2"|default:"0"}{else}0.00{/if}</td>
</tr> </tr>
{/section} {/section}
</tbody> </tbody>

View File

@ -19,7 +19,7 @@
<td>{if $data.is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$data.username|default:"unknown"|escape}{/if}</td> <td>{if $data.is_anonymous|default:"0" == 1 && $GLOBAL.userdata.is_admin|default:"0" == 0}anonymous{else}{$data.username|default:"unknown"|escape}{/if}</td>
<td align="right">{$data.valid|number_format}</td> <td align="right">{$data.valid|number_format}</td>
<td align="right">{$data.invalid|number_format}</td> <td align="right">{$data.invalid|number_format}</td>
<td align="right" style="padding-right: 25px;">{if $data.invalid > 0 }{($data.invalid / $data.valid * 100)|number_format:"2"|default:"0"}{else}0.00{/if}</td> <td align="right" style="padding-right: 25px;">{if $data.invalid > 0 }{(($data.invalid / ($data.valid + $data.invalid) * 100)|number_format:"2"|default:"0"}{else}0.00{/if}</td>
</tr> </tr>
{/foreach} {/foreach}
</tbody> </tbody>