diff --git a/public/include/classes/bitcoinwrapper.class.php b/public/include/classes/bitcoinwrapper.class.php index eb6d55e0..7b4372b4 100644 --- a/public/include/classes/bitcoinwrapper.class.php +++ b/public/include/classes/bitcoinwrapper.class.php @@ -25,19 +25,32 @@ class BitcoinWrapper extends BitcoinClient { public function getblockcount() { $this->oDebug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__)) return $data; - return $this->memcache->setCache(__FUNCTION__, parent::getblockcount()); + return $this->memcache->setCache(__FUNCTION__, parent::getblockcount(), 30); } public function getdifficulty() { $this->oDebug->append("STA " . __METHOD__, 4); if ($data = $this->memcache->get(__FUNCTION__)) return $data; - return $this->memcache->setCache(__FUNCTION__, parent::getdifficulty()); + $data = parent::getdifficulty(); + // Check for PoS/PoW coins + if (is_array($data) && array_key_exists('proof-of-work', $data)) + $data = $data['proof-of-work']; + return $this->memcache->setCache(__FUNCTION__, $data, 30); } public function getestimatedtime($iCurrentPoolHashrate) { $this->oDebug->append("STA " . __METHOD__, 4); if ($iCurrentPoolHashrate == 0) return 0; if ($data = $this->memcache->get(__FUNCTION__)) return $data; - $dDifficulty = parent::getdifficulty(); - return $this->memcache->setCache(__FUNCTION__, $dDifficulty * pow(2,32) / $iCurrentPoolHashrate); + $dDifficulty = $this->getdifficulty(); + return $this->memcache->setCache(__FUNCTION__, $dDifficulty * pow(2,32) / $iCurrentPoolHashrate, 30); + } + public function getnetworkhashps() { + $this->oDebug->append("STA " . __METHOD__, 4); + if ($data = $this->memcache->get(__FUNCTION__)) return $data; + try { $dNetworkHashrate = $this->query('getnetworkhashps') / 1000; } catch (Exception $e) { + // Maybe we are SHA + try { $dNetworkHashrate = $this->query('gethashespersec') / 1000; } catch (Exception $e) { return false; } + } + return $this->memcache->setCache(__FUNCTION__, $dNetworkHashrate, 30); } } diff --git a/public/include/pages/api/getdifficulty.inc.php b/public/include/pages/api/getdifficulty.inc.php index e84d4045..54cc7ac9 100644 --- a/public/include/pages/api/getdifficulty.inc.php +++ b/public/include/pages/api/getdifficulty.inc.php @@ -11,12 +11,7 @@ $id = $user->checkApiKey($_REQUEST['api_key']); // Fetch data from wallet if ($bitcoin->can_connect() === true){ - if (!$dDifficulty = $memcache->get('dDifficulty')) { - $dDifficulty = $bitcoin->query('getdifficulty'); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; - $memcache->set('dDifficulty', $dDifficulty); - } + $dDifficulty = $bitcoin->getdifficulty(); } else { $iDifficulty = 1; } diff --git a/public/include/pages/api/getpoolstatus.inc.php b/public/include/pages/api/getpoolstatus.inc.php index 662f80fb..55864e0b 100644 --- a/public/include/pages/api/getpoolstatus.inc.php +++ b/public/include/pages/api/getpoolstatus.inc.php @@ -19,8 +19,6 @@ $aShares['valid'] > 0 ? $dEfficiency = round((100 - (100 / $aShares['valid'] * $ // Fetch RPC data if ($bitcoin->can_connect() === true){ $dDifficulty = $bitcoin->getdifficulty(); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; $iBlock = $bitcoin->getblockcount(); $dNetworkHashrate = $bitcoin->query('getnetworkhashps'); } else { diff --git a/public/include/pages/api/public.inc.php b/public/include/pages/api/public.inc.php index 7e7c1f6e..e8be4181 100644 --- a/public/include/pages/api/public.inc.php +++ b/public/include/pages/api/public.inc.php @@ -11,7 +11,7 @@ $aLastBlock = $block->getLast(); $aShares = $statistics->getRoundShares(); // RPC Calls -$bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->query('getnetworkhashps') : $dNetworkHashrate = 0; +$bitcoin->can_connect() === true ? $dNetworkHashrate = $bitcoin->getnetworkhashps() : $dNetworkHashrate = 0; echo json_encode( array( diff --git a/public/include/pages/statistics.inc.php b/public/include/pages/statistics.inc.php index 076ce66f..be328545 100644 --- a/public/include/pages/statistics.inc.php +++ b/public/include/pages/statistics.inc.php @@ -7,9 +7,7 @@ if (!defined('SECURITY')) if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { $debug->append('No cached version available, fetching from backend', 3); if ($bitcoin->can_connect() === true){ - $dDifficulty = $bitcoin->query('getdifficulty'); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; + $dDifficulty = $bitcoin->getdifficulty(); $iBlock = $bitcoin->query('getblockcount'); } else { $dDifficulty = 1; diff --git a/public/include/pages/statistics/pool.inc.php b/public/include/pages/statistics/pool.inc.php index 0e2383d0..5416b984 100644 --- a/public/include/pages/statistics/pool.inc.php +++ b/public/include/pages/statistics/pool.inc.php @@ -8,8 +8,6 @@ if (!$smarty->isCached('master.tpl', $smarty_cache_key)) { // Fetch data from wallet if ($bitcoin->can_connect() === true){ $dDifficulty = $bitcoin->getdifficulty(); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; $iBlock = $bitcoin->getblockcount(); is_int($iBlock) && $iBlock > 0 ? $sBlockHash = $bitcoin->query('getblockhash', $iBlock) : $sBlockHash = ''; } else { diff --git a/public/include/smarty_globals.inc.php b/public/include/smarty_globals.inc.php index f66e7e34..acde330c 100644 --- a/public/include/smarty_globals.inc.php +++ b/public/include/smarty_globals.inc.php @@ -14,17 +14,10 @@ $aRoundShares = 1; // Only run these if the user is logged in $aRoundShares = $statistics->getRoundShares(); if ($bitcoin->can_connect() === true) { - $dDifficulty = $bitcoin->query('getdifficulty'); - if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) - $dDifficulty = $dDifficulty['proof-of-work']; - try { $dNetworkHashrate = $bitcoin->query('getnetworkhashps') / 1000; } catch (Exception $e) { - // Maybe we are SHA - try { $dNetworkHashrate = $bitcoin->query('gethashespersec') / 1000; } catch (Exception $e) { - $dNetworkHashrate = 0; - } - $dNetworkHashrate = 0; - } + $dDifficulty = $bitcoin->getdifficulty(); + $dNetworkHashrate = $bitcoin->getnetworkhashps(); } else { + $dDifficulty = 0; $dNetworkHashrate = 0; }