Merge pull request #680 from obigal/pplns-payout-blockavg-fix
pplns_payout block average fix when multiple blocks found during a payou...
This commit is contained in:
commit
0af2b9002e
@ -46,7 +46,7 @@ foreach ($aAllBlocks as $iIndex => $aBlock) {
|
||||
// We support some dynamic share targets but fall back to our fixed value
|
||||
// Re-calculate after each run due to re-targets in this loop
|
||||
if ($config['pplns']['shares']['type'] == 'blockavg' && $block->getBlockCount() > 0) {
|
||||
$pplns_target = round($block->getAvgBlockShares($config['pplns']['blockavg']['blockcount']));
|
||||
$pplns_target = round($block->getAvgBlockShares($aBlock['height'], $config['pplns']['blockavg']['blockcount']));
|
||||
} else {
|
||||
$pplns_target = $config['pplns']['shares']['default'];
|
||||
}
|
||||
|
||||
@ -109,9 +109,9 @@ class Block {
|
||||
* @param limit int Maximum blocks to check
|
||||
* @return data float Float value of average shares
|
||||
**/
|
||||
public function getAvgBlockShares($limit=1) {
|
||||
$stmt = $this->mysqli->prepare("SELECT AVG(x.shares) AS average FROM (SELECT shares FROM $this->table ORDER BY height DESC LIMIT ?) AS x");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||
public function getAvgBlockShares($height, $limit=1) {
|
||||
$stmt = $this->mysqli->prepare("SELECT AVG(x.shares) AS average FROM (SELECT shares FROM $this->table WHERE height <= ? ORDER BY height DESC LIMIT ?) AS x");
|
||||
if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $height, $limit) && $stmt->execute() && $result = $stmt->get_result())
|
||||
return (float)$result->fetch_object()->average;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ if (@$_SESSION['USERDATA']['id']) {
|
||||
$aGlobal['userdata']['est_payout'] = 0;
|
||||
}
|
||||
case 'pplns':
|
||||
if ($iAvgBlockShares = round($block->getAvgBlockShares($config['pplns']['blockavg']['blockcount']))) {
|
||||
if ($aLastBlock = $block->getLast() && $iAvgBlockShares = round($block->getAvgBlockShares($aLastBlock['height'], $config['pplns']['blockavg']['blockcount']))) {
|
||||
$aGlobal['pplns']['target'] = $iAvgBlockShares;
|
||||
} else {
|
||||
$aGlobal['pplns']['target'] = $config['pplns']['shares']['default'];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user