Skip to content

Commit

Permalink
Merge pull request #2738 from MPOS/development
Browse files Browse the repository at this point in the history
UPDATE : Development to Master
  • Loading branch information
TheSerapher authored May 24, 2018
2 parents 8fa8d6c + e5b1ec5 commit 236cccd
Show file tree
Hide file tree
Showing 35 changed files with 177 additions and 116 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "delboy1978uk/mpos",
"name": "MPOS/php-mpos",
"description": "MPOS stands for Mining Portal Open Source. A unified mining interface for various Scrypt and SHA256d Crypto-currencies!",
"require-dev": {
"codeception/codeception": "~2.0"
},
"authors": [
{
"name": "Derek Stephen McLean",
"email": "delboy1978uk@gmail.com"
"name": "Sebastian Grewe",
"email": "sebastian.grewe@gmail.com"
}
],
"require": {
Expand Down
6 changes: 5 additions & 1 deletion include/autoloader.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
(SECURITY == "*)WT#&YHfd" && SECHASH_CHECK) ? die("public/index.php -> Set a new SECURITY value to continue") : 0;
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;

require_once(INCLUDE_DIR . '/../vendor/autoload.php');
if (file_exists(INCLUDE_DIR . '/../vendor/autoload.php')) {
require_once(INCLUDE_DIR . '/../vendor/autoload.php');
} else {
die("Unable to load vendor libraries, please run `php composer.phar install` in root folder.");
}

// Default classes
require_once(INCLUDE_DIR . '/lib/KLogger.php');
Expand Down
4 changes: 3 additions & 1 deletion include/classes/bitcoin.class.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,15 @@ public function __construct($scheme, $username, $password, $address = "localhost
* The check is done by calling the server's getinfo() method and checking
* for a fault.
*
* To turn code compatible with BTC >= 0.16, getmininginfo() method used instead of getinfo()
*
* @return mixed boolean TRUE if successful, or a fault string otherwise
* @access public
* @throws none
*/
public function can_connect() {
try {
$r = $this->getinfo();
$r = $this->getmininginfo();
} catch (Exception $e) {
return $e->getMessage();
}
Expand Down
18 changes: 17 additions & 1 deletion include/classes/bitcoinwrapper.class.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,29 @@ public function __construct($type, $username, $password, $host, $debug_level, $d
public function getinfo() {
$this->oDebug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
return $this->memcache->setCache(__FUNCTION__, parent::getinfo(), 30);
try {
return $this->memcache->setCache(__FUNCTION__, parent::getnetworkinfo()+parent::getmininginfo()+parent::getwalletinfo(), 30);
} catch (Exception $e) {
$this->oDebug->append("DEPRECATED : RPC version < 0.16, fallback to `getinfo` RPC call", 2);
return $this->memcache->setCache(__FUNCTION__, parent::getinfo(), 30);
}
}

public function is_testnet() {
$this->oDebug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
if (!(parent::getblockchaininfo()))
return $this->memcache->setCache(__FUNCTION__, parent::is_testnet(), 30);
else
return $this->memcache->setCache(__FUNCTION__, parent::getblockchaininfo()['chain'] == 'test', 30);
}

public function getmininginfo() {
$this->oDebug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
return $this->memcache->setCache(__FUNCTION__, parent::getmininginfo(), 30);
}

public function getblockcount() {
$this->oDebug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
Expand Down
2 changes: 1 addition & 1 deletion include/classes/block.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function setShareId($block_id, $share_id) {
* @return bool
**/
public function setShares($block_id, $shares=NULL) {
$field = array( 'name' => 'shares', 'value' => $shares, 'type' => 'i');
$field = array( 'name' => 'shares', 'value' => $shares, 'type' => 'd');
return $this->updateSingle($block_id, $field);
}

Expand Down
2 changes: 1 addition & 1 deletion include/classes/coins/coin_base.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function calcHashrate($shares, $interval) {
* according to our configuration difficulty
**/
public function calcEstaimtedShares($dDifficulty) {
return (int)round(pow(2, (32 - $this->target_bits)) * $dDifficulty, 0);
return (float)round(pow(2, (32 - $this->target_bits)) * $dDifficulty, $this->share_difficulty_precision);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions include/classes/statistics.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function getBlocksFound($limit=10) {
b.*,
a.username AS finder,
a.is_anonymous AS is_anonymous,
ROUND(difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . "), 0) AS estshares
ROUND(difficulty * POW(2, 32 - " . $this->coin->getTargetBits() . "), " . $this->coin->getShareDifficultyPrecision() . ") AS estshares
FROM " . $this->block->getTableName() . " AS b
LEFT JOIN " . $this->user->getTableName() . " AS a
ON b.account_id = a.id
Expand Down Expand Up @@ -203,7 +203,7 @@ public function getBlocksSolvedbyWorker($account_id, $limit=25) {
public function updateShareStatistics($aStats, $iBlockId) {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, block_id) VALUES (?, ?, ?, ?)");
if ($this->checkStmt($stmt) && $stmt->bind_param('iiii', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true;
if ($this->checkStmt($stmt) && $stmt->bind_param('iddi', $aStats['id'], $aStats['valid'], $aStats['invalid'], $iBlockId) && $stmt->execute()) return true;
return $this->sqlError();
}

Expand All @@ -213,7 +213,7 @@ public function updateShareStatistics($aStats, $iBlockId) {
public function insertPPLNSStatistics($aStats, $iBlockId) {
$this->debug->append("STA " . __METHOD__, 4);
$stmt = $this->mysqli->prepare("INSERT INTO $this->table (account_id, valid, invalid, pplns_valid, pplns_invalid, block_id) VALUES (?, ?, ?, ?, ?, ?)");
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;
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;
return $this->sqlError();
}

Expand Down Expand Up @@ -261,12 +261,12 @@ public function getCurrentShareRate($interval=180) {
SELECT
(
(
SELECT ROUND(SUM(difficulty) / ?, 2) AS sharerate
SELECT ROUND(SUM(difficulty) / ?, " . $this->coin->getShareDifficultyPrecision() . ") AS sharerate
FROM " . $this->share->getTableName() . "
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND)
AND our_result = 'Y'
) + (
SELECT ROUND(SUM(difficulty) / ?, 2) AS sharerate
SELECT ROUND(SUM(difficulty) / ?, " . $this->coin->getShareDifficultyPrecision() . ") AS sharerate
FROM " . $this->share->getArchiveTableName() . "
WHERE time > DATE_SUB(now(), INTERVAL ? SECOND)
AND our_result = 'Y'
Expand Down Expand Up @@ -470,7 +470,7 @@ public function fetchAllUserMiningStats($interval=180) {
a.username AS account,
COUNT(DISTINCT t1.username) AS workers,
IFNULL(SUM(t1.difficulty), 0) AS shares,
ROUND(SUM(t1.difficulty) / ?, 2) AS sharerate,
ROUND(SUM(t1.difficulty) / ?, " . $this->coin->getShareDifficultyPrecision() . ") AS sharerate,
IFNULL(AVG(IF(difficulty=0, pow(2, (" . $this->config['difficulty'] . " - 16)), difficulty)), 0) AS avgsharediff
FROM (
SELECT
Expand Down
2 changes: 1 addition & 1 deletion include/classes/worker.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function getWorkers($account_id, $interval=600) {
while ($row = $result->fetch_assoc()) {
$row['hashrate'] = round($this->coin->calcHashrate($row['shares'], $interval), 2);
if ($row['count_all'] > 0) {
$row['difficulty'] = round($row['shares'] / $row['count_all'], 2);
$row['difficulty'] = round($row['shares'] / $row['count_all'], $this->coin->getShareDifficultyPrecision());
} else {
$row['difficulty'] = 0.00;
}
Expand Down
Loading

0 comments on commit 236cccd

Please sign in to comment.