Merge pull request #1695 from MPOS/reward-average
[ADDED] Use block averages for payout estimates
This commit is contained in:
commit
5d65f04515
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -249,4 +249,4 @@ $config['smarty']['cache_lifetime'] = 30;
|
||||
**/
|
||||
$config['system']['load']['max'] = 10.0;
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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'],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user