diff --git a/public/include/classes/block.class.php b/public/include/classes/block.class.php index 52cbfebf..ef0cdf7f 100644 --- a/public/include/classes/block.class.php +++ b/public/include/classes/block.class.php @@ -239,6 +239,21 @@ class Block extends Base { $field = array( 'name' => 'accounted', 'value' => 1, 'type' => 'i'); return $this->updateSingle($block_id, $field); } + + /** + * Fetch the average amount of the past N blocks + * @param limit int Block limit + * @param return mixed Block array or false + **/ + public function getAverageAmount($limit=10) { + $stmt = $this->mysqli->prepare("SELECT AVG(amount) as avg_amount FROM ( SELECT amount FROM $this->table ORDER BY id DESC LIMIT ?) AS t1"); + if ($this->checkStmt($stmt) && $stmt->bind_param('i', $limit) && $stmt->execute() && $result = $stmt->get_result()) { + return $result->fetch_object()->avg_amount; + } else { + $this->setErrorMessage('Failed to get average award from blocks'); + return $this->sqlError(); + } + } } // Automatically load our class for furhter usage diff --git a/public/include/classes/statistics.class.php b/public/include/classes/statistics.class.php index a9696d35..63d2f711 100644 --- a/public/include/classes/statistics.class.php +++ b/public/include/classes/statistics.class.php @@ -810,7 +810,8 @@ class Statistics extends Base { $this->debug->append("STA " . __METHOD__, 4); if ($this->config['payout_system'] != 'pps') { if (@$value1['valid'] > 0 && @$value2['valid'] > 0) { - $aEstimates['block'] = round(( (int)$value2['valid'] / (int)$value1['valid'] ) * (float)$this->config['reward'], 8); + $this->config['reward_type'] == 'fixed' ? $reward = $this->config['reward'] : $reward = $this->block->getAverageAmount(); + $aEstimates['block'] = round(( (int)$value2['valid'] / (int)$value1['valid'] ) * (float)$reward, 8); $bNoFees == 0 ? $aEstimates['fee'] = round(((float)$this->config['fees'] / 100) * (float)$aEstimates['block'], 8) : $aEstimates['fee'] = 0; $aEstimates['donation'] = round((( (float)$dDonate / 100) * ((float)$aEstimates['block'] - (float)$aEstimates['fee'])), 8); $aEstimates['payout'] = round((float)$aEstimates['block'] - (float)$aEstimates['donation'] - (float)$aEstimates['fee'], 8); diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index 9a7c45eb..49d7d259 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -249,4 +249,4 @@ $config['smarty']['cache_lifetime'] = 30; **/ $config['system']['load']['max'] = 10.0; -?> \ No newline at end of file +?> diff --git a/public/include/pages/statistics/pool.inc.php b/public/include/pages/statistics/pool.inc.php index 84fb3546..37ede713 100644 --- a/public/include/pages/statistics/pool.inc.php +++ b/public/include/pages/statistics/pool.inc.php @@ -42,6 +42,9 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $dTimeSinceLast = 0; } + // Block average reward or fixed + $reward = $config['reward_type'] == 'fixed' ? $config['reward'] : $block->getAverageAmount(); + // Round progress $iEstShares = $statistics->getEstimatedShares($dDifficulty); $aRoundShares = $statistics->getRoundShares(); @@ -73,7 +76,7 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $smarty->assign("LASTBLOCK", 0); } $smarty->assign("DIFFICULTY", $dDifficulty); - $smarty->assign("REWARD", $config['reward']); + $smarty->assign("REWARD", $reward); } else { $debug->append('Using cached page', 3); } diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index a772718c..6dddd2a0 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -60,7 +60,7 @@ $aGlobal = array( 'roundshares' => $aRoundShares, 'fees' => $config['fees'], 'confirmations' => $config['confirmations'], - 'reward' => $config['reward'], + 'reward' => $config['reward_type'] == 'fixed' ? $config['reward'] : $block->getAverageAmount(), 'price' => $setting->getValue('price'), 'twofactor' => $config['twofactor'], 'csrf' => $config['csrf'],