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'); die('Hacking attempt');
class BitcoinWrapper extends BitcoinClient { class BitcoinWrapper extends BitcoinClient {
var $type, $username, $password, $host, $memcache; public function __construct($type, $username, $password, $host, $debug, $memcache) {
public function __construct($type, $username, $password, $host, $memcache) {
$this->type = $type; $this->type = $type;
$this->username = $username; $this->username = $username;
$this->password = $password; $this->password = $password;
$this->host = $host; $this->host = $host;
// $this->debug is already used
$this->oDebug = $debug;
$this->memcache = $memcache; $this->memcache = $memcache;
return parent::__construct($this->type, $this->username, $this->password, $this->host); 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 * Wrap variouns methods to add caching
**/ **/
public function getblockcount() { public function getblockcount() {
$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());
} }
public function getdifficulty() { public function getdifficulty() {
$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()); return $this->memcache->setCache(__FUNCTION__, parent::getdifficulty());
} }
public function getestimatedtime($iCurrentPoolHashrate) { public function getestimatedtime($iCurrentPoolHashrate) {
$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 = parent::getdifficulty();
@ -34,4 +38,4 @@ class BitcoinWrapper extends BitcoinClient {
} }
// Load this wrapper // 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 // Fetch data from litecoind
if ($bitcoin->can_connect() === true){ if ($bitcoin->can_connect() === true){
if (!$dDifficulty = $memcache->get('dDifficulty')) { $dDifficulty = $bitcoin->getdifficulty();
$dDifficulty = $bitcoin->query('getdifficulty'); $iBlock = $bitcoin->getblockcount();
$memcache->set('dDifficulty', $dDifficulty);
}
if (!$iBlock = $memcache->get('iBlock')) {
$iBlock = $bitcoin->query('getblockcount');
$memcache->set('iBlock', $iBlock);
}
} else { } else {
$iDifficulty = 1; $iDifficulty = 1;
$iBlock = 0; $iBlock = 0;
@ -24,7 +18,7 @@ if ($bitcoin->can_connect() === true){
$aContributorsShares = $statistics->getTopContributors('shares', 15); $aContributorsShares = $statistics->getTopContributors('shares', 15);
// Top hash contributors // Top hash contributors
$aContributorsHashes = $statistics->getTopContributors('hashes', 15); $aContributorsHashes = $statistics->getTopContributors('hashes', 15);
// Grab the last 10 blocks found // Grab the last 10 blocks found
$iLimit = 10; $iLimit = 10;

View File

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