Skip to content

Commit e45a29c

Browse files
committed
Merge pull request #2019 from MPOS/development
Development to Master
2 parents b2d8c18 + e7d5397 commit e45a29c

File tree

356 files changed

+40021
-1857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

356 files changed

+40021
-1857
lines changed

cronjobs/etc/logrotate.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"./logs/*.txt" {
1+
"./logs/*/*.txt" {
22
copytruncate
33
rotate 7
44
compress

cronjobs/payouts.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@
4646

4747
// Fetch unconfirmed amount from blocks table
4848
empty($config['network_confirmations']) ? $confirmations = 120 : $confirmations = $config['network_confirmations'];
49-
$aBlocksUnconfirmed = $block->getAllUnconfirmed($confirmations);
50-
$dBlocksUnconfirmedBalance = 0;
49+
if ($config['getbalancewithunconfirmed']) {
50+
$aBlocksUnconfirmed = $block->getAllUnconfirmed($confirmations);
51+
$dBlocksUnconfirmedBalance = 0;
5152
if (!empty($aBlocksUnconfirmed))foreach ($aBlocksUnconfirmed as $aData) $dBlocksUnconfirmedBalance += $aData['amount'];
52-
53-
$dWalletBalance -= $dBlocksUnconfirmedBalance;
54-
53+
$dWalletBalance -= $dBlocksUnconfirmedBalance;
54+
}
5555
// Fetch Newmint
5656
$aGetInfo = $bitcoin->getinfo();
5757
if (is_array($aGetInfo) && array_key_exists('newmint', $aGetInfo)) {
@@ -133,12 +133,12 @@
133133

134134
// Fetch unconfirmed amount from blocks table
135135
empty($config['network_confirmations']) ? $confirmations = 120 : $confirmations = $config['network_confirmations'];
136-
$aBlocksUnconfirmed = $block->getAllUnconfirmed($confirmations);
137-
$dBlocksUnconfirmedBalance = 0;
136+
if ($config['getbalancewithunconfirmed']) {
137+
$aBlocksUnconfirmed = $block->getAllUnconfirmed($confirmations);
138+
$dBlocksUnconfirmedBalance = 0;
138139
if (!empty($aBlocksUnconfirmed))foreach ($aBlocksUnconfirmed as $aData) $dBlocksUnconfirmedBalance += $aData['amount'];
139-
140-
$dWalletBalance -= $dBlocksUnconfirmedBalance;
141-
140+
$dWalletBalance -= $dBlocksUnconfirmedBalance;
141+
}
142142
// Fetch Newmint
143143
$aGetInfo = $bitcoin->getinfo();
144144
if (is_array($aGetInfo) && array_key_exists('newmint', $aGetInfo)) {

cronjobs/pps_payout.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
}
6464

6565
// Per-share value to be paid out to users
66-
$pps_value = round($pps_reward / (pow(2, $config['target_bits']) * $dDifficulty), 12);
66+
$pps_value = round($coin->calcPPSValue($pps_reward, $dDifficulty), 12);
6767

6868
// Find our last share accounted and last inserted share for PPS calculations
6969
if (!$iPreviousShareId = $setting->getValue('pps_last_share_id')) {
@@ -105,9 +105,8 @@
105105
continue;
106106
}
107107

108-
// MPOS uses a base difficulty setting to avoid showing weightened shares
109-
// Since we need weightened shares here, we go back to the proper value for payouts
110-
$aData['payout'] = round($aData['valid'] * pow(2, ($config['difficulty'] - 16)) * $pps_value, 12);
108+
// Payout for this user
109+
$aData['payout'] = round($aData['valid'] * $pps_value, 12);
111110

112111
// Defaults
113112
$aData['fee' ] = 0;
@@ -120,7 +119,7 @@
120119
$aData['donation'] = round($user->getDonatePercent($user->getUserId($aData['username'])) / 100 * ( $aData['payout'] - $aData['fee']), 12);
121120

122121
$log->logInfo(sprintf(
123-
$strLogMask, $aData['id'], $aData['username'], $aData['invalid'], $aData['valid'] * pow(2, ($config['difficulty'] - 16)),
122+
$strLogMask, $aData['id'], $aData['username'], $aData['invalid'], $aData['valid'],
124123
number_format($pps_value, 12), number_format($aData['payout'], 12), number_format($aData['donation'], 12), number_format($aData['fee'], 12)
125124
));
126125

cronjobs/run-crons.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
echo "Please be aware: This cron is deprecated and will be removed. Please read: https://github.com/MPOS/php-mpos/wiki/Cronjobs#setup"
4+
sleep 2
35

46
#########################
57
# #

cronjobs/tickerupdate.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,26 @@
3333
$strLogMask = "| %-25.25s | %15.15s | %8.8s | %-6.6s | %-80.80s |";
3434
$log->logInfo(sprintf($strLogMask, 'Method', 'Value', 'Runtime', 'Status', 'Message'));
3535

36+
empty($config['price']['enabled']) ? $tickerupdate = false : $tickerupdate = $config['price']['enabled'];
37+
3638
// Fetch latest coin price via API call
3739
$start = microtime(true);
38-
$message = 'Updated latest ' . $config['currency'] . ' price from ' . $config['price']['url'] . ' API';
39-
$status = 'OK';
40-
if ($price = $tools->getPrice()) {
41-
if (!$setting->setValue('price', $price)) {
42-
$message = 'Unable to store new price value: ' . $setting->getCronError();
40+
if ($tickerupdate) {
41+
$message = 'Updated latest ' . $config['currency'] . ' price from ' . $config['price']['url'] . ' API';
42+
$status = 'OK';
43+
if ($price = $tools->getPrice()) {
44+
if (!$setting->setValue('price', $price)) {
45+
$message = 'Unable to store new price value: ' . $setting->getCronError();
46+
$status = 'ERROR';
47+
}
48+
} else {
49+
$message = 'Failed to fetch price from API: ' . $tools->getCronError();
4350
$status = 'ERROR';
4451
}
4552
} else {
46-
$message = 'Failed to fetch price from API: ' . $tools->getCronError();
47-
$status = 'ERROR';
53+
$message = 'Tickerupdate is disabled';
54+
$status = 'OK';
55+
$price = 0;
4856
}
4957
$log->logInfo(sprintf($strLogMask, 'Price Update', $price, number_format(microtime(true) - $start, 3), $status, $message));
5058

public/include/admin_checks.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,16 @@
127127

128128
// display the errors
129129
foreach ($enotice as $en) {
130-
$_SESSION['POPUP'][] = array('CONTENT' => $en, 'TYPE' => 'info');
130+
$_SESSION['POPUP'][] = array('CONTENT' => $en, 'TYPE' => 'alert alert-info');
131131
}
132132
if (!count($notice) && !count($error)) {
133-
$_SESSION['POPUP'][] = array('CONTENT' => 'The config options we checked seem OK', 'TYPE' => 'success');
133+
$_SESSION['POPUP'][] = array('CONTENT' => 'The config options we checked seem OK', 'TYPE' => 'alert alert-success');
134134
} else {
135135
foreach ($notice as $n) {
136-
$_SESSION['POPUP'][] = array('CONTENT' => $n, 'TYPE' => 'warning');
136+
$_SESSION['POPUP'][] = array('CONTENT' => $n, 'TYPE' => 'alert alert-warning');
137137
}
138138
foreach ($error as $e) {
139-
$_SESSION['POPUP'][] = array('CONTENT' => $e, 'TYPE' => 'errormsg');
139+
$_SESSION['POPUP'][] = array('CONTENT' => $e, 'TYPE' => 'alert alert-danger');
140140
}
141141
}
142142
}

public/include/autoloader.inc.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
(SECURITY == "*)WT#&YHfd" && SECHASH_CHECK) ? die("public/index.php -> Set a new SECURITY value to continue") : 0;
33
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
44

5-
// SHA/Scrypt check
6-
if (empty($config['algorithm']) || $config['algorithm'] == 'scrypt') {
7-
$config['target_bits'] = 16;
8-
} else {
9-
$config['target_bits'] = 32;
10-
}
11-
125
// Default classes
136
require_once(INCLUDE_DIR . '/lib/KLogger.php');
147
require_once(CLASS_DIR . '/logger.class.php');
@@ -20,24 +13,28 @@
2013
require_once(INCLUDE_DIR . '/config/memcache_keys.inc.php');
2114
require_once(INCLUDE_DIR . '/config/error_codes.inc.php');
2215

23-
// We need to load these two first
16+
// We need to load these first
2417
require_once(CLASS_DIR . '/base.class.php');
18+
require_once(CLASS_DIR . '/coins/coin_base.class.php');
2519
require_once(CLASS_DIR . '/setting.class.php');
2620

27-
// We need this one in here to properly set our theme
28-
require_once(INCLUDE_DIR . '/lib/Mobile_Detect.php');
21+
// Now decide on which coin class to load and instantiate
22+
if (file_exists(CLASS_DIR . '/coins/coin_' . $config['algorithm'] . '.class.php')) {
23+
require_once(CLASS_DIR . '/coins/coin_' . $config['algorithm'] . '.class.php');
24+
$coin = new Coin();
25+
$coin->setConfig($config);
26+
} else {
27+
die('Unable to load your coins class definition for ' . $config['algorithm']);
28+
}
2929

3030
// Detect device
31-
if ($detect->isMobile() && $setting->getValue('website_mobile_theme')) {
32-
// Set to mobile theme
33-
$setting->getValue('website_mobile_theme') ? $theme = $setting->getValue('website_mobile_theme') : $theme = 'mobile';
34-
} else if ( PHP_SAPI == 'cli') {
31+
if ( PHP_SAPI == 'cli') {
3532
// Create a new compile folder just for crons
3633
// We call mail templates directly anyway
3734
$theme = 'cron';
3835
} else {
3936
// Use configured theme, fallback to default theme
40-
$setting->getValue('website_theme') ? $theme = $setting->getValue('website_theme') : $theme = 'mpos';
37+
$setting->getValue('website_theme') ? $theme = $setting->getValue('website_theme') : $theme = 'bootstrap';
4138
}
4239
define('THEME', $theme);
4340

@@ -73,4 +70,4 @@
7370
require_once(INCLUDE_DIR . '/lib/Michelf/Markdown.php');
7471
require_once(INCLUDE_DIR . '/lib/scrypt.php');
7572

76-
?>
73+
?>

public/include/bootstrap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
$quickstartlink = "<a href='https://github.com/MPOS/php-mpos/wiki/Quick-Start-Guide' title='MPOS Quick Start Guide'>Quick Start Guide</a>";
1212

1313
// Include our configuration (holding defines for the requires)
14-
if (!include_once(BASEPATH . 'include/config/global.inc.dist.php')) die('Unable to load base global config - '.$quickstartlink);
15-
if (!@include_once(BASEPATH . 'include/config/global.inc.php')) die('Unable to load your global config - '.$quickstartlink);
14+
if (!include_once(BASEPATH . 'include/config/global.inc.dist.php')) die('Unable to load base global config from ['.BASEPATH . 'include/config/global.inc.dist.php' . '] - '.$quickstartlink);
15+
if (!@include_once(BASEPATH . 'include/config/global.inc.php')) die('Unable to load your global config from ['.BASEPATH . 'include/config/global.inc.php' . '] - '.$quickstartlink);
1616

1717
// load our security configs
18-
if (!include_once(BASEPATH . 'include/config/security.inc.dist.php')) die('Unable to load base security config - '.$quickstartlink);
18+
if (!include_once(BASEPATH . 'include/config/security.inc.dist.php')) die('Unable to load base security config from ['.BASEPATH . 'include/config/security.inc.dist.php' . '] - '.$quickstartlink);
1919
if (@file_exists(BASEPATH . 'include/config/security.inc.php')) include_once(BASEPATH . 'include/config/security.inc.php');
2020

2121
// start our session, we need it for smarty caching
@@ -36,4 +36,4 @@
3636
// We include all needed files here, even though our templates could load them themself
3737
require_once(INCLUDE_DIR . '/autoloader.inc.php');
3838

39-
?>
39+
?>

public/include/classes/base.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public function getTableName() {
1919
public function setDebug($debug) {
2020
$this->debug = $debug;
2121
}
22+
public function setCoin($coin) {
23+
$this->coin = $coin;
24+
}
2225
public function setLog($log) {
2326
$this->log = $log;
2427
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;
3+
4+
5+
/**
6+
* Our coin base class that we extend our other coins from
7+
*
8+
* We are implementing all basic coin methods into this class but it
9+
* must be extended for customized coins.
10+
**/
11+
class CoinBase extends Base {
12+
// Our coins target bits
13+
protected $target_bits = NULL;
14+
15+
/**
16+
* Read our target bits
17+
**/
18+
public function getTargetBits() {
19+
return $this->target_bits;
20+
}
21+
22+
/**
23+
* Calculate the PPS value for this coin
24+
* WARNING: Get this wrong and you will over- or underpay your miners!
25+
**/
26+
public function calcPPSValue($pps_reward, $dDifficulty) {
27+
return ($pps_reward / (pow(2, $this->target_bits) * $dDifficulty));
28+
}
29+
30+
/**
31+
* Calculate our hashrate based on shares inserted to DB
32+
* We use diff1 share values, not a baseline one
33+
**/
34+
public function calcHashrate($shares, $interval) {
35+
return $shares * pow(2, $this->target_bits) / $interval / 1000;
36+
}
37+
38+
/**
39+
* Calculate estimated shares of this coin, this is using baseline
40+
* according to our configuration difficulty
41+
**/
42+
public function calcEstaimtedShares($dDifficulty) {
43+
return (int)round(pow(2, (32 - $this->target_bits)) * $dDifficulty, 0);
44+
}
45+
46+
/**
47+
* Calculate our networks expected time per block
48+
**/
49+
public function calcNetworkExpectedTimePerBlock($dDifficulty, $dNetworkHashrate) {
50+
return pow(2, 32) * $dDifficulty / $dNetworkHashrate;
51+
}
52+
/**
53+
* Calculate next expected difficulty based on current difficulty
54+
**/
55+
public function calcExpectedNextDifficulty($dDifficulty, $dNetworkHashrate) {
56+
return round($dDifficulty * $this->config['cointarget'] / $this->calcNetworkExpectedTimePerBlock($dDifficulty, $dNetworkHashrate), 8);
57+
}
58+
}
59+
60+
?>

0 commit comments

Comments
 (0)