Skip to content

Commit a7a731d

Browse files
committed
[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
1 parent 674b12e commit a7a731d

File tree

14 files changed

+35
-30
lines changed

14 files changed

+35
-30
lines changed

cronjobs/pplns_payout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
}
4040

4141
// Fetch precision
42-
$precision = $setting->getValue('system_coin_precision', 12);
43-
$table_precision = $setting->getValue('system_coin_precision', 12) + 3;
42+
$precision = $coin->getCoinValuePrevision();
43+
$table_precision = $coin->getCoinValuePrevision() + 3;
4444

4545
$log->logDebug('Starting PPLNS payout process');
4646
$count = 0;

cronjobs/pps_payout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@
8989

9090
if (!empty($aAccountShares)) {
9191
// Runtime information for this payout
92-
$precision = $setting->getValue('system_coin_precision', 12);
93-
$table_precision = $setting->getValue('system_coin_precision', 12) + 3;
92+
$precision = $coin->getCoinValuePrevision();
93+
$table_precision = $coin->getCoinValuePrevision() + 3;
9494
$log->logInfo('Runtime information for this payout');
9595
$strLogMask = "| %-15.15s | %15.15s | %15.15s | %${table_precision}.${table_precision}s | %3.3s |";
9696
$log->logInfo(sprintf($strLogMask, 'PPS reward type', 'Reward Base', 'Difficulty', 'PPS Value', 'Precision'));

cronjobs/proportional_payout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
}
4040

4141
// Fetch precision
42-
$precision = $setting->getValue('system_coin_precision', 12);
43-
$table_precision = $setting->getValue('system_coin_precision', 12) + 3;
42+
$precision = $coin->getCoinValuePrevision();
43+
$table_precision = $coin->getCoinValuePrevision() + 3;
4444

4545
$count = 0;
4646
// Table header for account shares

include/classes/coins/coin_base.class.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,23 @@ class CoinBase extends Base {
1515
// Our coins share difficulty precision
1616
protected $share_difficulty_precision = 0;
1717

18+
// Our coin value precision, mostly used on frontend
19+
protected $coin_value_precision = 8;
20+
1821
/**
1922
* Read our target bits
2023
**/
2124
public function getTargetBits() {
2225
return $this->target_bits;
2326
}
2427

28+
/**
29+
* Read our coin value precision
30+
**/
31+
public function getCoinValuePrevision() {
32+
return $this->coin_value_precision;
33+
}
34+
2535
/**
2636
* Read our share difficulty precision
2737
**/

include/classes/coins/coin_sha256d.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
**/
99
class Coin extends CoinBase {
1010
protected $target_bits = 32;
11+
protected $coin_value_precision = 20;
1112
}
1213

1314
?>

include/classes/transaction.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Transaction extends Base {
1616
* @return bool
1717
**/
1818
public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL, $txid=NULL) {
19-
$amount = number_format($amount, $this->setting->getValue('system_coin_precision', 12), '.', '');
19+
$amount = number_format($amount, $this->coin->getCoinValuePrevision(), '.', '');
2020
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, amount, block_id, type, coin_address, txid) VALUES (?, ?, ?, ?, ?, ?)");
2121
if ($this->checkStmt($stmt) && $stmt->bind_param("isisss", $account_id, $amount, $block_id, $type, $coin_address, $txid) && $stmt->execute()) {
2222
$this->insert_id = $stmt->insert_id;
@@ -480,6 +480,7 @@ public function getMPQueue($limit=250) {
480480
$transaction->setNotification($notification);
481481
$transaction->setSetting($setting);
482482
$transaction->setDebug($debug);
483+
$transaction->setCoin($coin);
483484
$transaction->setCoinAddress($coin_address);
484485
$transaction->setMysql($mysqli);
485486
$transaction->setConfig($config);

include/config/admin_settings.inc.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,6 @@
308308
'name' => 'system_error_email', 'value' => $setting->getValue('system_error_email'),
309309
'tooltip' => 'The email address for system errors notifications, like cronjobs failures.'
310310
);
311-
$aSettings['system'][] = array(
312-
'display' => 'Coin Precision', 'type' => 'text',
313-
'size' => 5,
314-
'default' => '12',
315-
'name' => 'system_coin_precision', 'value' => $setting->getValue('system_coin_precision'),
316-
'tooltip' => 'How do we round any coin values throughout MPOS. Defaults to 12 digits.'
317-
);
318311
$aSettings['system'][] = array(
319312
'display' => 'Date format string', 'type' => 'text',
320313
'size' => 25,

include/pages/dashboard.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
}
5050

5151
// Make it available in Smarty
52-
$smarty->assign('PRECISION', $setting->getValue('system_coin_precision', 12));
52+
$smarty->assign('PRECISION', $coin->getCoinValuePrevision());
5353
$smarty->assign('BLOCKSFOUND', $aLastBlocks);
5454
$smarty->assign('DISABLED_DASHBOARD', $setting->getValue('disable_dashboard'));
5555
$smarty->assign('DISABLED_DASHBOARD_API', $setting->getValue('disable_dashboard_api'));

include/smarty_globals.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@
177177
case 'pps':
178178
$aGlobal['userdata']['pps']['unpaidshares'] = $statistics->getUserUnpaidPPSShares($_SESSION['USERDATA']['username'], $_SESSION['USERDATA']['id'], $setting->getValue('pps_last_share_id'));
179179
// We use coin precision + 8 to display PPS value
180-
$aGlobal['ppsvalue'] = number_format($statistics->getPPSValue(), $setting->getValue('system_coin_precision', 12) + 8);
180+
$aGlobal['ppsvalue'] = number_format($statistics->getPPSValue(), $coin->getCoinValuePrevision() + 8);
181181
$aGlobal['poolppsvalue'] = $aGlobal['ppsvalue'] * pow(2, $config['difficulty'] - 16);
182182
$aGlobal['userdata']['estimates'] = $statistics->getUserEstimates($aGlobal['userdata']['sharerate'], $aGlobal['userdata']['sharedifficulty'], $aGlobal['userdata']['donate_percent'], $aGlobal['userdata']['no_fees'], $aGlobal['ppsvalue']);
183183
break;

include/version.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
33

44
define('MPOS_VERSION', '0.0.4');
5-
define('DB_VERSION', '0.0.12');
5+
define('DB_VERSION', '0.0.13');
66
define('CONFIG_VERSION', '0.0.8');
77
define('HASH_VERSION', 1);
88

0 commit comments

Comments
 (0)