commit
a572d0cea0
@ -153,19 +153,42 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
|||||||
$iRoundShares = $iNewRoundShares;
|
$iRoundShares = $iNewRoundShares;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merge round shares and pplns shares arrays
|
||||||
|
$aTotalAccountShares = NULL;
|
||||||
|
foreach($aAccountShares as $key => $aData) {
|
||||||
|
$aData['pplns_valid'] = $aData['valid'];
|
||||||
|
$aData['pplns_invalid'] = $aData['invalid'];
|
||||||
|
$aData['valid'] = 0;
|
||||||
|
$aData['invalid'] = 0;
|
||||||
|
$aTotalAccountShares[$aData['username']] = $aData;
|
||||||
|
}
|
||||||
|
foreach($aRoundAccountShares as $key => $aTempData) {
|
||||||
|
if (array_key_exists($aTempData['username'], $aTotalAccountShares)) {
|
||||||
|
$aTotalAccountShares[$aTempData['username']]['valid'] = $aTempData['valid'];
|
||||||
|
$aTotalAccountShares[$aTempData['username']]['invalid'] = $aTempData['invalid'];
|
||||||
|
} else {
|
||||||
|
$aTempData['pplns_valid'] = 0;
|
||||||
|
$aTempData['pplns_invalid'] = 0;
|
||||||
|
$aTotalAccountShares[$aTempData['username']] = $aTempData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Table header for account shares
|
// Table header for account shares
|
||||||
$log->logInfo("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\tFee");
|
$log->logInfo("ID\tUsername\tValid\tInvalid\tPercentage\tPayout\t\tDonation\tFee");
|
||||||
|
|
||||||
// Loop through all accounts that have found shares for this round
|
// Loop through all accounts that have found shares for this round
|
||||||
foreach ($aAccountShares as $key => $aData) {
|
foreach ($aTotalAccountShares as $key => $aData) {
|
||||||
// Skip entries that have no account ID, user deleted?
|
// Skip entries that have no account ID, user deleted?
|
||||||
if (empty($aData['id'])) {
|
if (empty($aData['id'])) {
|
||||||
$log->logInfo('User ' . $aData['username'] . ' does not have an associated account, skipping');
|
$log->logInfo('User ' . $aData['username'] . ' does not have an associated account, skipping');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($aData['pplns_valid'] == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Payout based on PPLNS target shares, proportional payout for all users
|
// Payout based on PPLNS target shares, proportional payout for all users
|
||||||
$aData['percentage'] = round(( 100 / $iRoundShares) * $aData['valid'], 8);
|
$aData['percentage'] = round(( 100 / $iRoundShares) * $aData['pplns_valid'], 8);
|
||||||
$aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8);
|
$aData['payout'] = round(( $aData['percentage'] / 100 ) * $dReward, 8);
|
||||||
// Defaults
|
// Defaults
|
||||||
$aData['fee' ] = 0;
|
$aData['fee' ] = 0;
|
||||||
@ -179,33 +202,13 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
|||||||
// Verbose output of this users calculations
|
// Verbose output of this users calculations
|
||||||
$log->logInfo($aData['id'] . "\t" .
|
$log->logInfo($aData['id'] . "\t" .
|
||||||
$aData['username'] . "\t" .
|
$aData['username'] . "\t" .
|
||||||
$aData['valid'] . "\t" .
|
$aData['pplns_valid'] . "\t" .
|
||||||
$aData['invalid'] . "\t" .
|
$aData['pplns_invalid'] . "\t" .
|
||||||
number_format($aData['percentage'], 8) . "\t" .
|
number_format($aData['percentage'], 8) . "\t" .
|
||||||
number_format($aData['payout'], 8) . "\t" .
|
number_format($aData['payout'], 8) . "\t" .
|
||||||
number_format($aData['donation'], 8) . "\t" .
|
number_format($aData['donation'], 8) . "\t" .
|
||||||
number_format($aData['fee'], 8));
|
number_format($aData['fee'], 8));
|
||||||
|
|
||||||
// Add full round share statistics, not just PPLNS
|
|
||||||
foreach ($aRoundAccountShares as $key => $aRoundData) {
|
|
||||||
if ($aRoundData['username'] == $aData['username'])
|
|
||||||
if (!$statistics->updateShareStatistics($aRoundData, $aBlock['id']))
|
|
||||||
$log->logError('Failed to update share statistics for ' . $aData['username'] . ': ' . $statistics->getCronError());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add PPLNS share statistics
|
|
||||||
foreach ($aAccountShares as $key => $aRoundData) {
|
|
||||||
if ($aRoundData['username'] == $aData['username']){
|
|
||||||
if (@$statistics->getIdShareStatistics($aRoundData, $aBlock['id'])){
|
|
||||||
if (!$statistics->updatePPLNSShareStatistics($aRoundData, $aBlock['id']))
|
|
||||||
$log->logError('Failed to update pplns statistics for ' . $aData['username'] . ': ' . $statistics->getCronError());
|
|
||||||
} else {
|
|
||||||
if (!$statistics->insertPPLNSShareStatistics($aRoundData, $aBlock['id']))
|
|
||||||
$log->logError('Failed to insert pplns statistics for ' . $aData['username'] . ': ' . $statistics->getCronError());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add new credit transaction
|
// Add new credit transaction
|
||||||
if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id']))
|
if (!$transaction->addTransaction($aData['id'], $aData['payout'], 'Credit', $aBlock['id']))
|
||||||
$log->logFatal('Failed to insert new Credit transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError());
|
$log->logFatal('Failed to insert new Credit transaction to database for ' . $aData['username'] . ': ' . $transaction->getCronError());
|
||||||
@ -219,6 +222,15 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
|||||||
$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 full round share statistics
|
||||||
|
foreach ($aTotalAccountShares as $key => $aRoundData) {
|
||||||
|
if (empty($aRoundData['id'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!$statistics->insertPPLNSStatistics($aRoundData, $aBlock['id']))
|
||||||
|
$log->logError('Failed to insert share statistics for ' . $aRoundData['username'] . ': ' . $statistics->getCronError());
|
||||||
|
}
|
||||||
|
|
||||||
// Store this blocks height as last accounted for
|
// Store this blocks height as last accounted for
|
||||||
$setting->setValue('last_accounted_block_id', $aBlock['id']);
|
$setting->setValue('last_accounted_block_id', $aBlock['id']);
|
||||||
|
|
||||||
|
|||||||
@ -107,7 +107,7 @@ class RoundStats extends Base {
|
|||||||
FROM " . $this->statistics->getTableName() . " AS s
|
FROM " . $this->statistics->getTableName() . " AS s
|
||||||
LEFT JOIN " . $this->block->getTableName() . " AS b ON s.block_id = b.id
|
LEFT JOIN " . $this->block->getTableName() . " AS b ON s.block_id = b.id
|
||||||
LEFT JOIN " . $this->user->getTableName() . " AS a ON a.id = s.account_id
|
LEFT JOIN " . $this->user->getTableName() . " AS a ON a.id = s.account_id
|
||||||
WHERE b.height = ?
|
WHERE b.height = ? AND s.valid > 0
|
||||||
GROUP BY username ASC
|
GROUP BY username ASC
|
||||||
ORDER BY valid DESC
|
ORDER BY valid DESC
|
||||||
");
|
");
|
||||||
@ -136,7 +136,7 @@ class RoundStats extends Base {
|
|||||||
FROM " . $this->statistics->getTableName() . " AS s
|
FROM " . $this->statistics->getTableName() . " AS s
|
||||||
LEFT JOIN " . $this->block->getTableName() . " AS b ON s.block_id = b.id
|
LEFT JOIN " . $this->block->getTableName() . " AS b ON s.block_id = b.id
|
||||||
LEFT JOIN " . $this->user->getTableName() . " AS a ON a.id = s.account_id
|
LEFT JOIN " . $this->user->getTableName() . " AS a ON a.id = s.account_id
|
||||||
WHERE b.height = ?
|
WHERE b.height = ? AND s.pplns_valid > 0
|
||||||
GROUP BY username ASC
|
GROUP BY username ASC
|
||||||
ORDER BY pplns_valid DESC
|
ORDER BY pplns_valid DESC
|
||||||
");
|
");
|
||||||
|
|||||||
@ -202,36 +202,12 @@ class Statistics extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update user statistics of valid and invalid pplns shares
|
* insert user round and pplns shares merged array
|
||||||
**/
|
**/
|
||||||
public function updatePPLNSShareStatistics($aStats, $iBlockId) {
|
public function insertPPLNSStatistics($aStats, $iBlockId) {
|
||||||
$this->debug->append("STA " . __METHOD__, 4);
|
$this->debug->append("STA " . __METHOD__, 4);
|
||||||
$stmt = $this->mysqli->prepare("
|
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, pplns_valid, pplns_invalid, block_id) VALUES (?, ?, ?, ?, ?, ?)");
|
||||||
UPDATE $this->table SET pplns_valid = ?, pplns_invalid = ? WHERE account_id = ? AND block_id = ?");
|
if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $aStats['pplns_valid'], $aStats['pplns_invalid'], $iBlockId) && $stmt->execute()) return true;
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $aStats['valid'], $aStats['invalid'], $aStats['id'], $iBlockId) && $stmt->execute()) return true;
|
|
||||||
return $this->sqlError();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* insert user statistics of valid and invalid pplns shares "rbpplns"
|
|
||||||
**/
|
|
||||||
public function insertPPLNSShareStatistics($aStats, $iBlockId) {
|
|
||||||
$this->debug->append("STA " . __METHOD__, 4);
|
|
||||||
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, pplns_valid, pplns_invalid, block_id) VALUES (?, 0, 0, ?, ?, ?)");
|
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true;
|
|
||||||
return $this->sqlError();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch the share ID from stats for rbpplns
|
|
||||||
**/
|
|
||||||
function getIdShareStatistics($aStats, $iBlockId) {
|
|
||||||
$stmt = $this->mysqli->prepare("
|
|
||||||
SELECT id AS id FROM $this->table
|
|
||||||
WHERE account_id = ? AND block_id = ?
|
|
||||||
");
|
|
||||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $aStats['id'], $iBlockId) && $stmt->execute() && $result = $stmt->get_result())
|
|
||||||
return $result->fetch_object()->id;
|
|
||||||
return $this->sqlError();
|
return $this->sqlError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -116,7 +116,11 @@ class User extends Base {
|
|||||||
$this->setErrorMessage("Invalid username or password.");
|
$this->setErrorMessage("Invalid username or password.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
|
if (!filter_var($username, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
$this->debug->append("Not an e-mail address, rejecting login", 2);
|
||||||
|
$this->setErrorMessage("Please login with your e-mail address");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
$this->debug->append("Username is an e-mail: $username", 2);
|
$this->debug->append("Username is an e-mail: $username", 2);
|
||||||
if (!$username = $this->getUserNameByEmail($username)) {
|
if (!$username = $this->getUserNameByEmail($username)) {
|
||||||
$this->setErrorMessage("Invalid username or password.");
|
$this->setErrorMessage("Invalid username or password.");
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
// Make sure we are called from index.php
|
// Make sure we are called from index.php
|
||||||
if (!defined('SECURITY')) die('Hacking attempt');
|
if (!defined('SECURITY')) die('Hacking attempt');
|
||||||
|
|
||||||
define('MPOS_VERSION', '0.0.1');
|
define('MPOS_VERSION', '0.0.2');
|
||||||
define('DB_VERSION', '0.0.3');
|
define('DB_VERSION', '0.0.3');
|
||||||
define('CONFIG_VERSION', '0.0.4');
|
define('CONFIG_VERSION', '0.0.4');
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
<form action="{$smarty.server.SCRIPT_NAME}?page=login" method="post" id="loginForm" data-ajax="false">
|
<form action="{$smarty.server.SCRIPT_NAME}?page=login" method="post" id="loginForm" data-ajax="false">
|
||||||
<input type="hidden" name="to" value="{($smarty.request.to|default:"{$smarty.server.SCRIPT_NAME}?page=dashboard")|escape}" />
|
<input type="hidden" name="to" value="{($smarty.request.to|default:"{$smarty.server.SCRIPT_NAME}?page=dashboard")|escape}" />
|
||||||
{if $GLOBAL.csrf.enabled && $GLOBAL.csrf.forms.login}<input type="hidden" name="ctoken" value="{$CTOKEN}" />{/if}
|
{if $GLOBAL.csrf.enabled && $GLOBAL.csrf.forms.login}<input type="hidden" name="ctoken" value="{$CTOKEN}" />{/if}
|
||||||
<p><input type="text" name="username" value="" id="userForm" maxlength="20"></p>
|
<p><label for="userForm">Email</label><input type="text" name="username" value="" id="userForm"></p>
|
||||||
<p><input type="password" name="password" value="" id="passForm" maxlength="20"></p>
|
<p><label for="passForm">Password</label><input type="password" name="password" value="" id="passForm"></p>
|
||||||
<center>{nocache}{$RECAPTCHA|default:"" nofilter}{/nocache}</center>
|
<center>{nocache}{$RECAPTCHA|default:"" nofilter}{/nocache}</center>
|
||||||
<center><p><input type="submit" value="Login"></p></center>
|
<center><p><input type="submit" value="Login"></p></center>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<header><h3>Login with existing account</h3></header>
|
<header><h3>Login with existing account</h3></header>
|
||||||
<div class="module_content">
|
<div class="module_content">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label>Username or E-Mail</label>
|
<label>E-Mail</label>
|
||||||
<input type="text" name="username" size="22" maxlength="100" value="{$smarty.request.username|default:""|escape}" placeholder="Your username or email" required />
|
<input type="text" name="username" size="22" maxlength="100" value="{$smarty.request.username|default:""|escape}" placeholder="Your username or email" required />
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
{if $GLOBAL.csrf.enabled && $GLOBAL.csrf.forms.login}<input type="hidden" name="ctoken" value="{$CTOKEN}" />{/if}
|
{if $GLOBAL.csrf.enabled && $GLOBAL.csrf.forms.login}<input type="hidden" name="ctoken" value="{$CTOKEN}" />{/if}
|
||||||
<input type="hidden" name="to" value="{$smarty.server.SCRIPT_NAME}?page=dashboard" />
|
<input type="hidden" name="to" value="{$smarty.server.SCRIPT_NAME}?page=dashboard" />
|
||||||
<fieldset2 class="small">
|
<fieldset2 class="small">
|
||||||
<label>Username</label>
|
<label>E-Mail</label>
|
||||||
<input type="text" name="username" size="22" maxlength="100" required />
|
<input type="text" name="username" size="22" maxlength="100" required />
|
||||||
<fieldset2 class="small">
|
<fieldset2 class="small">
|
||||||
<label>Password</label>
|
<label>Password</label>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user