Use new BitcoinWrapper class, remove memcache calls

This commit is contained in:
Sebastian Grewe 2013-05-28 11:50:37 +02:00
parent 72207cf246
commit 510ce89338
3 changed files with 12 additions and 20 deletions

View File

@ -5,12 +5,13 @@ if (!defined('SECURITY'))
die('Hacking attempt');
class BitcoinWrapper extends BitcoinClient {
var $type, $username, $password, $host, $memcache;
public function __construct($type, $username, $password, $host, $memcache) {
public function __construct($type, $username, $password, $host, $debug, $memcache) {
$this->type = $type;
$this->username = $username;
$this->password = $password;
$this->host = $host;
// $this->debug is already used
$this->oDebug = $debug;
$this->memcache = $memcache;
return parent::__construct($this->type, $this->username, $this->password, $this->host);
}
@ -18,14 +19,17 @@ class BitcoinWrapper extends BitcoinClient {
* Wrap variouns methods to add caching
**/
public function getblockcount() {
$this->oDebug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
return $this->memcache->setCache(__FUNCTION__, parent::getblockcount());
}
public function getdifficulty() {
$this->oDebug->append("STA " . __METHOD__, 4);
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
return $this->memcache->setCache(__FUNCTION__, parent::getdifficulty());
}
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();
@ -34,4 +38,4 @@ class BitcoinWrapper extends BitcoinClient {
}
// Load this wrapper
$bitcoin = new BitcoinWrapper($config['wallet']['type'], $config['wallet']['username'], $config['wallet']['password'], $config['wallet']['host'], $memcache);
$bitcoin = new BitcoinWrapper($config['wallet']['type'], $config['wallet']['username'], $config['wallet']['password'], $config['wallet']['host'], $debug, $memcache);

View File

@ -6,14 +6,8 @@ if (!defined('SECURITY'))
// Fetch data from litecoind
if ($bitcoin->can_connect() === true){
if (!$dDifficulty = $memcache->get('dDifficulty')) {
$dDifficulty = $bitcoin->query('getdifficulty');
$memcache->set('dDifficulty', $dDifficulty);
}
if (!$iBlock = $memcache->get('iBlock')) {
$iBlock = $bitcoin->query('getblockcount');
$memcache->set('iBlock', $iBlock);
}
$dDifficulty = $bitcoin->getdifficulty();
$iBlock = $bitcoin->getblockcount();
} else {
$iDifficulty = 1;
$iBlock = 0;
@ -24,7 +18,7 @@ if ($bitcoin->can_connect() === true){
$aContributorsShares = $statistics->getTopContributors('shares', 15);
// Top hash contributors
$aContributorsHashes = $statistics->getTopContributors('hashes', 15);
$aContributorsHashes = $statistics->getTopContributors('hashes', 15);
// Grab the last 10 blocks found
$iLimit = 10;

View File

@ -6,14 +6,8 @@ if (!defined('SECURITY'))
// Fetch data from litecoind
if ($bitcoin->can_connect() === true){
if (!$dDifficulty = $memcache->get('dDifficulty')) {
$dDifficulty = $bitcoin->query('getdifficulty');
$memcache->set('dDifficulty', $dDifficulty);
}
if (!$iBlock = $memcache->get('iBlock')) {
$iBlock = $bitcoin->query('getblockcount');
$memcache->set('iBlock', $iBlock);
}
$dDifficulty = $bitcoin->getdifficulty();
$iBlock = $bitcoin->getblockcount();
} else {
$iDifficulty = 1;
$iBlock = 0;