Bitcoin Wrapper improvements
* [FEATURE] Allow for PoS/PoW Detecion in getdifficulty * [FEATURE] Allow for SHA detecion in getnetworkhashps * [IMRPOVEMENT] Added caching for bitcoin values (30s only) * Will reduce the amount of RPC calls for high load pages
This commit is contained in:
parent
8abe371fba
commit
bbe39228e1
@ -25,19 +25,32 @@ class BitcoinWrapper extends BitcoinClient {
|
|||||||
public function getblockcount() {
|
public function getblockcount() {
|
||||||
$this->oDebug->append("STA " . __METHOD__, 4);
|
$this->oDebug->append("STA " . __METHOD__, 4);
|
||||||
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
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() {
|
public function getdifficulty() {
|
||||||
$this->oDebug->append("STA " . __METHOD__, 4);
|
$this->oDebug->append("STA " . __METHOD__, 4);
|
||||||
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
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) {
|
public function getestimatedtime($iCurrentPoolHashrate) {
|
||||||
$this->oDebug->append("STA " . __METHOD__, 4);
|
$this->oDebug->append("STA " . __METHOD__, 4);
|
||||||
if ($iCurrentPoolHashrate == 0) return 0;
|
if ($iCurrentPoolHashrate == 0) return 0;
|
||||||
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
|
||||||
$dDifficulty = parent::getdifficulty();
|
$dDifficulty = $this->getdifficulty();
|
||||||
return $this->memcache->setCache(__FUNCTION__, $dDifficulty * pow(2,32) / $iCurrentPoolHashrate);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,17 +14,10 @@ $aRoundShares = 1;
|
|||||||
// Only run these if the user is logged in
|
// Only run these if the user is logged in
|
||||||
$aRoundShares = $statistics->getRoundShares();
|
$aRoundShares = $statistics->getRoundShares();
|
||||||
if ($bitcoin->can_connect() === true) {
|
if ($bitcoin->can_connect() === true) {
|
||||||
$dDifficulty = $bitcoin->query('getdifficulty');
|
$dDifficulty = $bitcoin->getdifficulty();
|
||||||
if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty))
|
$dNetworkHashrate = $bitcoin->getnetworkhashps();
|
||||||
$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;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
$dDifficulty = 0;
|
||||||
$dNetworkHashrate = 0;
|
$dNetworkHashrate = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user