diff --git a/cronjobs/pplns_payout.php b/cronjobs/pplns_payout.php index 5f1840b7..832f6e59 100755 --- a/cronjobs/pplns_payout.php +++ b/cronjobs/pplns_payout.php @@ -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; diff --git a/cronjobs/pps_payout.php b/cronjobs/pps_payout.php index deeeb095..f35f1560 100755 --- a/cronjobs/pps_payout.php +++ b/cronjobs/pps_payout.php @@ -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')); diff --git a/cronjobs/proportional_payout.php b/cronjobs/proportional_payout.php index 95daf0ff..faf4e53a 100755 --- a/cronjobs/proportional_payout.php +++ b/cronjobs/proportional_payout.php @@ -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 diff --git a/include/classes/coins/coin_base.class.php b/include/classes/coins/coin_base.class.php index b9242822..ab84c311 100644 --- a/include/classes/coins/coin_base.class.php +++ b/include/classes/coins/coin_base.class.php @@ -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 **/ diff --git a/include/classes/coins/coin_sha256d.class.php b/include/classes/coins/coin_sha256d.class.php index 1147770e..2b830263 100644 --- a/include/classes/coins/coin_sha256d.class.php +++ b/include/classes/coins/coin_sha256d.class.php @@ -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; } ?> diff --git a/include/classes/transaction.class.php b/include/classes/transaction.class.php index 0b3abf3e..194ca486 100644 --- a/include/classes/transaction.class.php +++ b/include/classes/transaction.class.php @@ -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); diff --git a/include/config/admin_settings.inc.php b/include/config/admin_settings.inc.php index 32cd082e..475c2448 100644 --- a/include/config/admin_settings.inc.php +++ b/include/config/admin_settings.inc.php @@ -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, diff --git a/include/pages/dashboard.inc.php b/include/pages/dashboard.inc.php index 519d7667..56747bea 100644 --- a/include/pages/dashboard.inc.php +++ b/include/pages/dashboard.inc.php @@ -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')); diff --git a/include/smarty_globals.inc.php b/include/smarty_globals.inc.php index e2785a4e..8cd45a77 100644 --- a/include/smarty_globals.inc.php +++ b/include/smarty_globals.inc.php @@ -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; diff --git a/include/version.inc.php b/include/version.inc.php index a4e0d533..2b7ea18a 100644 --- a/include/version.inc.php +++ b/include/version.inc.php @@ -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); diff --git a/sql/000_base_structure.sql b/sql/000_base_structure.sql index f007ca55..f4ddebcf 100644 --- a/sql/000_base_structure.sql +++ b/sql/000_base_structure.sql @@ -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, diff --git a/templates/bootstrap/dashboard/js/api.tpl b/templates/bootstrap/dashboard/js/api.tpl index 07344d74..9e4a9d54 100644 --- a/templates/bootstrap/dashboard/js/api.tpl +++ b/templates/bootstrap/dashboard/js/api.tpl @@ -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}); diff --git a/templates/bootstrap/dashboard/round_statistics/pps/round.tpl b/templates/bootstrap/dashboard/round_statistics/pps/round.tpl index 14ab1584..7fc95e6c 100644 --- a/templates/bootstrap/dashboard/round_statistics/pps/round.tpl +++ b/templates/bootstrap/dashboard/round_statistics/pps/round.tpl @@ -7,7 +7,7 @@
{$GLOBAL.userdata.estimates.hours1|number_format:12}
+{$GLOBAL.userdata.estimates.hours1|number_format:$PRECISION}
{$GLOBAL.config.currency} 1 Hour Estimated Earnings
@@ -22,7 +22,7 @@{$GLOBAL.userdata.estimates.hours24|number_format:12}
+{$GLOBAL.userdata.estimates.hours24|number_format:$PRECISION}
{$GLOBAL.config.currency} 24 Hour Estimated Earnings
@@ -37,7 +37,7 @@{$GLOBAL.userdata.estimates.days7|number_format:12}
+{$GLOBAL.userdata.estimates.days7|number_format:$PRECISION}
{$GLOBAL.config.currency} 7 Days Estimated Earnings
@@ -52,7 +52,7 @@{$GLOBAL.userdata.estimates.days14|number_format:12}
+{$GLOBAL.userdata.estimates.days14|number_format:$PRECISION}
{$GLOBAL.config.currency} 14 Days Estimated Earnings
@@ -67,7 +67,7 @@{$GLOBAL.userdata.estimates.days30|number_format:12}
+{$GLOBAL.userdata.estimates.days30|number_format:$PRECISION}
{$GLOBAL.config.currency} 30 Days Estimated Earnings
diff --git a/upgrade/definitions/0.0.12_to_0.0.13.inc.php b/upgrade/definitions/0.0.12_to_0.0.13.inc.php index b81b87ce..6c198bb9 100644 --- a/upgrade/definitions/0.0.12_to_0.0.13.inc.php +++ b/upgrade/definitions/0.0.12_to_0.0.13.inc.php @@ -1,5 +1,5 @@ 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, '<')) {