Skip to content

Commit 236cccd

Browse files
authored
Merge pull request #2738 from MPOS/development
UPDATE : Development to Master
2 parents 8fa8d6c + e5b1ec5 commit 236cccd

35 files changed

+177
-116
lines changed

composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"name": "delboy1978uk/mpos",
2+
"name": "MPOS/php-mpos",
33
"description": "MPOS stands for Mining Portal Open Source. A unified mining interface for various Scrypt and SHA256d Crypto-currencies!",
44
"require-dev": {
55
"codeception/codeception": "~2.0"
66
},
77
"authors": [
88
{
9-
"name": "Derek Stephen McLean",
10-
"email": "delboy1978uk@gmail.com"
9+
"name": "Sebastian Grewe",
10+
"email": "sebastian.grewe@gmail.com"
1111
}
1212
],
1313
"require": {

include/autoloader.inc.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
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-
require_once(INCLUDE_DIR . '/../vendor/autoload.php');
5+
if (file_exists(INCLUDE_DIR . '/../vendor/autoload.php')) {
6+
require_once(INCLUDE_DIR . '/../vendor/autoload.php');
7+
} else {
8+
die("Unable to load vendor libraries, please run `php composer.phar install` in root folder.");
9+
}
610

711
// Default classes
812
require_once(INCLUDE_DIR . '/lib/KLogger.php');

include/classes/bitcoin.class.php

100644100755
+3-1
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,15 @@ public function __construct($scheme, $username, $password, $address = "localhost
284284
* The check is done by calling the server's getinfo() method and checking
285285
* for a fault.
286286
*
287+
* To turn code compatible with BTC >= 0.16, getmininginfo() method used instead of getinfo()
288+
*
287289
* @return mixed boolean TRUE if successful, or a fault string otherwise
288290
* @access public
289291
* @throws none
290292
*/
291293
public function can_connect() {
292294
try {
293-
$r = $this->getinfo();
295+
$r = $this->getmininginfo();
294296
} catch (Exception $e) {
295297
return $e->getMessage();
296298
}

include/classes/bitcoinwrapper.class.php

100644100755
+17-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,29 @@ public function __construct($type, $username, $password, $host, $debug_level, $d
2424
public function getinfo() {
2525
$this->oDebug->append("STA " . __METHOD__, 4);
2626
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
27-
return $this->memcache->setCache(__FUNCTION__, parent::getinfo(), 30);
27+
try {
28+
return $this->memcache->setCache(__FUNCTION__, parent::getnetworkinfo()+parent::getmininginfo()+parent::getwalletinfo(), 30);
29+
} catch (Exception $e) {
30+
$this->oDebug->append("DEPRECATED : RPC version < 0.16, fallback to `getinfo` RPC call", 2);
31+
return $this->memcache->setCache(__FUNCTION__, parent::getinfo(), 30);
32+
}
33+
}
34+
35+
public function is_testnet() {
36+
$this->oDebug->append("STA " . __METHOD__, 4);
37+
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
38+
if (!(parent::getblockchaininfo()))
39+
return $this->memcache->setCache(__FUNCTION__, parent::is_testnet(), 30);
40+
else
41+
return $this->memcache->setCache(__FUNCTION__, parent::getblockchaininfo()['chain'] == 'test', 30);
2842
}
43+
2944
public function getmininginfo() {
3045
$this->oDebug->append("STA " . __METHOD__, 4);
3146
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
3247
return $this->memcache->setCache(__FUNCTION__, parent::getmininginfo(), 30);
3348
}
49+
3450
public function getblockcount() {
3551
$this->oDebug->append("STA " . __METHOD__, 4);
3652
if ($data = $this->memcache->get(__FUNCTION__)) return $data;

include/classes/block.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public function setShareId($block_id, $share_id) {
237237
* @return bool
238238
**/
239239
public function setShares($block_id, $shares=NULL) {
240-
$field = array( 'name' => 'shares', 'value' => $shares, 'type' => 'i');
240+
$field = array( 'name' => 'shares', 'value' => $shares, 'type' => 'd');
241241
return $this->updateSingle($block_id, $field);
242242
}
243243

include/classes/coins/coin_base.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function calcHashrate($shares, $interval) {
6060
* according to our configuration difficulty
6161
**/
6262
public function calcEstaimtedShares($dDifficulty) {
63-
return (int)round(pow(2, (32 - $this->target_bits)) * $dDifficulty, 0);
63+
return (float)round(pow(2, (32 - $this->target_bits)) * $dDifficulty, $this->share_difficulty_precision);
6464
}
6565

6666
/**

include/classes/statistics.class.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function getBlocksFound($limit=10) {
111111
b.*,
112112
a.username AS finder,
113113
a.is_anonymous AS is_anonymous,
114-
ROUND(difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . "), 0) AS estshares
114+
ROUND(difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . "), " . $this->coin->getShareDifficultyPrecision() . ") AS estshares
115115
FROM " . $this->block->getTableName() . " AS b
116116
LEFT JOIN " . $this->user->getTableName() . " AS a
117117
ON b.account_id = a.id
@@ -203,7 +203,7 @@ public function getBlocksSolvedbyWorker($account_id, $limit=25) {
203203
public function updateShareStatistics($aStats, $iBlockId) {
204204
$this->debug->append("STA " . __METHOD__, 4);
205205
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?)");
206-
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true;
206+
if ($this->checkStmt($stmt) && $stmt->bind_param('iddi', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true;
207207
return $this->sqlError();
208208
}
209209

@@ -213,7 +213,7 @@ public function updateShareStatistics($aStats, $iBlockId) {
213213
public function insertPPLNSStatistics($aStats, $iBlockId) {
214214
$this->debug->append("STA " . __METHOD__, 4);
215215
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, pplns_valid, pplns_invalid, block_id) VALUES (?, ?, ?, ?, ?, ?)");
216-
if ($this->checkStmt($stmt) && $stmt->bind_param('iiiiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $aStats['pplns_valid'], $aStats['pplns_invalid'], $iBlockId) && $stmt->execute()) return true;
216+
if ($this->checkStmt($stmt) && $stmt->bind_param('iddddi', $aStats['id'], $aStats['valid'], $aStats['invalid'], $aStats['pplns_valid'], $aStats['pplns_invalid'], $iBlockId) && $stmt->execute()) return true;
217217
return $this->sqlError();
218218
}
219219

@@ -261,12 +261,12 @@ public function getCurrentShareRate($interval=180) {
261261
SELECT
262262
(
263263
(
264-
SELECT ROUND(SUM(difficulty) / ?, 2) AS sharerate
264+
SELECT ROUND(SUM(difficulty) / ?, " . $this->coin->getShareDifficultyPrecision() . ") AS sharerate
265265
FROM " . $this->share->getTableName() . "
266266
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND)
267267
AND our_result = 'Y'
268268
) + (
269-
SELECT ROUND(SUM(difficulty) / ?, 2) AS sharerate
269+
SELECT ROUND(SUM(difficulty) / ?, " . $this->coin->getShareDifficultyPrecision() . ") AS sharerate
270270
FROM " . $this->share->getArchiveTableName() . "
271271
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND)
272272
AND our_result = 'Y'
@@ -470,7 +470,7 @@ public function fetchAllUserMiningStats($interval=180) {
470470
a.username AS account,
471471
COUNT(DISTINCT t1.username) AS workers,
472472
IFNULL(SUM(t1.difficulty), 0) AS shares,
473-
ROUND(SUM(t1.difficulty) / ?, 2) AS sharerate,
473+
ROUND(SUM(t1.difficulty) / ?, " . $this->coin->getShareDifficultyPrecision() . ") AS sharerate,
474474
IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff
475475
FROM (
476476
SELECT

include/classes/worker.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function getWorkers($account_id, $interval=600) {
174174
while ($row = $result->fetch_assoc()) {
175175
$row['hashrate'] = round($this->coin->calcHashrate($row['shares'], $interval), 2);
176176
if ($row['count_all'] > 0) {
177-
$row['difficulty'] = round($row['shares'] / $row['count_all'], 2);
177+
$row['difficulty'] = round($row['shares'] / $row['count_all'], $this->coin->getShareDifficultyPrecision());
178178
} else {
179179
$row['difficulty'] = 0.00;
180180
}

0 commit comments

Comments
 (0)