[UPDATE] Working coin precision system

* [ADDED] New option to coin class to change coin value precision
* [UPDATE] SQL Transactions table from double to decimal(50,30)
* [REMOVED] Admin setting for coin value precision
* [UPDATE] JS files to honor coin precision
This commit is contained in:
Sebastian Grewe 2014-07-19 09:10:21 +02:00
parent 674b12e0d0
commit a7a731dcf1
14 changed files with 35 additions and 30 deletions

View File

@ -39,8 +39,8 @@ if (empty($aAllBlocks)) {
}
// Fetch precision
$precision = $setting->getValue('system_coin_precision', 12);
$table_precision = $setting->getValue('system_coin_precision', 12) + 3;
$precision = $coin->getCoinValuePrevision();
$table_precision = $coin->getCoinValuePrevision() + 3;
$log->logDebug('Starting PPLNS payout process');
$count = 0;

View File

@ -89,8 +89,8 @@ $log->logInfo("\tQuery Completed...");
if (!empty($aAccountShares)) {
// Runtime information for this payout
$precision = $setting->getValue('system_coin_precision', 12);
$table_precision = $setting->getValue('system_coin_precision', 12) + 3;
$precision = $coin->getCoinValuePrevision();
$table_precision = $coin->getCoinValuePrevision() + 3;
$log->logInfo('Runtime information for this payout');
$strLogMask = "| %-15.15s | %15.15s | %15.15s | %${table_precision}.${table_precision}s | %3.3s |";
$log->logInfo(sprintf($strLogMask, 'PPS reward type', 'Reward Base', 'Difficulty', 'PPS Value', 'Precision'));

View File

@ -39,8 +39,8 @@ if (empty($aAllBlocks)) {
}
// Fetch precision
$precision = $setting->getValue('system_coin_precision', 12);
$table_precision = $setting->getValue('system_coin_precision', 12) + 3;
$precision = $coin->getCoinValuePrevision();
$table_precision = $coin->getCoinValuePrevision() + 3;
$count = 0;
// Table header for account shares

View File

@ -15,6 +15,9 @@ class CoinBase extends Base {
// Our coins share difficulty precision
protected $share_difficulty_precision = 0;
// Our coin value precision, mostly used on frontend
protected $coin_value_precision = 8;
/**
* Read our target bits
**/
@ -22,6 +25,13 @@ class CoinBase extends Base {
return $this->target_bits;
}
/**
* Read our coin value precision
**/
public function getCoinValuePrevision() {
return $this->coin_value_precision;
}
/**
* Read our share difficulty precision
**/

View File

@ -8,6 +8,7 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
**/
class Coin extends CoinBase {
protected $target_bits = 32;
protected $coin_value_precision = 20;
}
?>

View File

@ -16,7 +16,7 @@ class Transaction extends Base {
* @return bool
**/
public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL, $txid=NULL) {
$amount = number_format($amount, $this->setting->getValue('system_coin_precision', 12), '.', '');
$amount = number_format($amount, $this->coin->getCoinValuePrevision(), '.', '');
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type, coin_address, txid) VALUES (?, ?, ?, ?, ?, ?)");
if ($this->checkStmt($stmt) && $stmt->bind_param("isisss", $account_id, $amount, $block_id, $type, $coin_address, $txid) && $stmt->execute()) {
$this->insert_id = $stmt->insert_id;
@ -480,6 +480,7 @@ $transaction->setMemcache($memcache);
$transaction->setNotification($notification);
$transaction->setSetting($setting);
$transaction->setDebug($debug);
$transaction->setCoin($coin);
$transaction->setCoinAddress($coin_address);
$transaction->setMysql($mysqli);
$transaction->setConfig($config);

View File

@ -308,13 +308,6 @@ $aSettings['system'][] = array(
'name' => 'system_error_email', 'value' => $setting->getValue('system_error_email'),
'tooltip' => 'The email address for system errors notifications, like cronjobs failures.'
);
$aSettings['system'][] = array(
'display' => 'Coin Precision', 'type' => 'text',
'size' => 5,
'default' => '12',
'name' => 'system_coin_precision', 'value' => $setting->getValue('system_coin_precision'),
'tooltip' => 'How do we round any coin values throughout MPOS. Defaults to 12 digits.'
);
$aSettings['system'][] = array(
'display' => 'Date format string', 'type' => 'text',
'size' => 25,

View File

@ -49,7 +49,7 @@ if ($user->isAuthenticated()) {
}
// Make it available in Smarty
$smarty->assign('PRECISION', $setting->getValue('system_coin_precision', 12));
$smarty->assign('PRECISION', $coin->getCoinValuePrevision());
$smarty->assign('BLOCKSFOUND', $aLastBlocks);
$smarty->assign('DISABLED_DASHBOARD', $setting->getValue('disable_dashboard'));
$smarty->assign('DISABLED_DASHBOARD_API', $setting->getValue('disable_dashboard_api'));

View File

@ -177,7 +177,7 @@ if (@$_SESSION['USERDATA']['id']) {
case 'pps':
$aGlobal['userdata']['pps']['unpaidshares'] = $statistics->getUserUnpaidPPSShares($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id'], $setting->getValue('pps_last_share_id'));
// We use coin precision + 8 to display PPS value
$aGlobal['ppsvalue'] = number_format($statistics->getPPSValue(), $setting->getValue('system_coin_precision', 12) + 8);
$aGlobal['ppsvalue'] = number_format($statistics->getPPSValue(), $coin->getCoinValuePrevision() + 8);
$aGlobal['poolppsvalue'] = $aGlobal['ppsvalue'] * pow(2, $config['difficulty'] - 16);
$aGlobal['userdata']['estimates'] = $statistics->getUserEstimates($aGlobal['userdata']['sharerate'], $aGlobal['userdata']['sharedifficulty'], $aGlobal['userdata']['donate_percent'], $aGlobal['userdata']['no_fees'], $aGlobal['ppsvalue']);
break;

View File

@ -2,7 +2,7 @@
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
define('MPOS_VERSION', '0.0.4');
define('DB_VERSION', '0.0.12');
define('DB_VERSION', '0.0.13');
define('CONFIG_VERSION', '0.0.8');
define('HASH_VERSION', 1);

View File

@ -226,7 +226,7 @@ CREATE TABLE IF NOT EXISTS `transactions` (
`account_id` int(255) unsigned NOT NULL,
`type` varchar(25) DEFAULT NULL,
`coin_address` varchar(255) DEFAULT NULL,
`amount` double(50,30) DEFAULT '0',
`amount` decimal(50,30) DEFAULT '0',
`block_id` int(255) DEFAULT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`txid` varchar(256) DEFAULT NULL,

View File

@ -141,11 +141,11 @@ $(document).ready(function(){
{/literal}{else}{literal}
$('#b-ppsunpaid').html(number_format(data.getdashboarddata.data.personal.shares.unpaid));
$('#b-ppsdiff').html(number_format(data.getdashboarddata.data.personal.sharedifficulty, 2));
$('#b-est1').html(number_format(data.getdashboarddata.data.personal.estimates.hours1, 12));
$('#b-est24hours').html(number_format(data.getdashboarddata.data.personal.estimates.hours24, 12));
$('#b-est7days').html(number_format(data.getdashboarddata.data.personal.estimates.days7, 12));
$('#b-est14days').html(number_format(data.getdashboarddata.data.personal.estimates.days14, 12));
$('#b-est30days').html(number_format(data.getdashboarddata.data.personal.estimates.days30, 12));
$('#b-est1').html(number_format(data.getdashboarddata.data.personal.estimates.hours1, {/literal}{$PRECISION}{literal}));
$('#b-est24hours').html(number_format(data.getdashboarddata.data.personal.estimates.hours24, {/literal}{$PRECISION}{literal}));
$('#b-est7days').html(number_format(data.getdashboarddata.data.personal.estimates.days7, {/literal}{$PRECISION}{literal}));
$('#b-est14days').html(number_format(data.getdashboarddata.data.personal.estimates.days14, {/literal}{$PRECISION}{literal}));
$('#b-est30days').html(number_format(data.getdashboarddata.data.personal.estimates.days30, {/literal}{$PRECISION}{literal}));
{/literal}{/if}{literal}
{/literal}{if $GLOBAL.config.payout_system == 'pplns'}{literal}
$('#b-pplns').html({/literal}{$GLOBAL.pplns.target}{literal});

View File

@ -7,7 +7,7 @@
</div>
<div class="circle-tile-content lightblue">
<div class="circle-tile-description text-faded">
<p class="h5" id="b-est1">{$GLOBAL.userdata.estimates.hours1|number_format:12}</p>
<p class="h5" id="b-est1">{$GLOBAL.userdata.estimates.hours1|number_format:$PRECISION}</p>
</div>
<div class="circle-tile-number text-faded">
<p class="h6">{$GLOBAL.config.currency} 1 Hour Estimated Earnings</p>
@ -22,7 +22,7 @@
</div>
<div class="circle-tile-content lightblue">
<div class="circle-tile-description text-faded">
<p class="h5" id="b-est24hours">{$GLOBAL.userdata.estimates.hours24|number_format:12}</p>
<p class="h5" id="b-est24hours">{$GLOBAL.userdata.estimates.hours24|number_format:$PRECISION}</p>
</div>
<div class="circle-tile-number text-faded">
<p class="h6">{$GLOBAL.config.currency} 24 Hour Estimated Earnings</p>
@ -37,7 +37,7 @@
</div>
<div class="circle-tile-content lightblue">
<div class="circle-tile-description text-faded">
<p class="h5" id="b-est7days">{$GLOBAL.userdata.estimates.days7|number_format:12}</p>
<p class="h5" id="b-est7days">{$GLOBAL.userdata.estimates.days7|number_format:$PRECISION}</p>
</div>
<div class="circle-tile-number text-faded">
<p class="h6">{$GLOBAL.config.currency} 7 Days Estimated Earnings</p>
@ -52,7 +52,7 @@
</div>
<div class="circle-tile-content lightblue">
<div class="circle-tile-description text-faded">
<p class="h5" id="b-est14days">{$GLOBAL.userdata.estimates.days14|number_format:12}</p>
<p class="h5" id="b-est14days">{$GLOBAL.userdata.estimates.days14|number_format:$PRECISION}</p>
</div>
<div class="circle-tile-number text-faded">
<p class="h6">{$GLOBAL.config.currency} 14 Days Estimated Earnings</p>
@ -67,7 +67,7 @@
</div>
<div class="circle-tile-content lightblue">
<div class="circle-tile-description text-faded">
<p class="h5" id="b-est30days">{$GLOBAL.userdata.estimates.days30|number_format:12}</p>
<p class="h5" id="b-est30days">{$GLOBAL.userdata.estimates.days30|number_format:$PRECISION}</p>
</div>
<div class="circle-tile-number text-faded">
<p class="h6">{$GLOBAL.config.currency} 30 Days Estimated Earnings</p>

View File

@ -1,5 +1,5 @@
<?php
function run_0012() {
function run_0013() {
// Ugly but haven't found a better way
global $setting, $config, $user, $mysqli, $transaction;
@ -9,7 +9,7 @@ function run_0012() {
$db_version_now = $setting->getValue('DB_VERSION'); // Our actual version installed
// Upgrade specific variables
$aSql[] = "ALTER TABLE " . $transaction->getTableName() . " CHANGE `amount` `amount` DOUBLE(60,30) NULL DEFAULT '0'";
$aSql[] = "ALTER TABLE " . $transaction->getTableName() . " CHANGE `amount` `amount` DECIMAL(50,30) NULL DEFAULT '0'";
$aSql[] = "UPDATE " . $setting->getTableName() . " SET value = '0.0.13' WHERE name = 'DB_VERSION'";
if ($db_version_now == $db_version_old && version_compare($db_version_now, DB_VERSION, '<')) {