Last active
August 29, 2015 14:00
-
-
Save lcherone/20708371fe07998a24d3 to your computer and use it in GitHub Desktop.
http://mattsmines.net/ OMC pool API class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
/** | |
* Simple OMC pool API class | |
* | |
* @author Lawrence Cherone | |
* @version 0.01 | |
*/ | |
class omc{ | |
public $totalz = array(); | |
/** | |
* Calls API and stores result in $_SESSION | |
* | |
* @param string $id | |
* @return string | |
*/ | |
function call_api($id){ | |
if(!isset($_SESSION[md5($id)])){ | |
$ch = curl_init(); | |
curl_setopt_array($ch, array( | |
CURLOPT_URL => 'http://mattsmines.net/OMC/get.php?id='.$id, | |
CURLOPT_TIMEOUT => 5, | |
CURLOPT_CONNECTTIMEOUT => 5, | |
CURLOPT_FAILONERROR => true, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_HEADER => false, | |
)); | |
$_SESSION[md5($id)] = curl_exec($ch); | |
} | |
return $_SESSION[md5($id)]; | |
} | |
/** | |
* Gets current pool hash speed and stores in $this->totalz scope. | |
* | |
* @param string $id | |
* @return int | |
*/ | |
function get_pool_hash($id){ | |
if(!isset($this->totalz[$id])){ | |
$result = $this->call_api($id); | |
if(substr($result, -3) == 'h/s'){ | |
$this->totalz[$id] = (int) $result; | |
}else{ | |
$this->totalz[$id] = 0; | |
} | |
} | |
return $this->totalz[$id]; | |
} | |
/** | |
* Display queryied pools as string | |
* | |
* @return string | |
*/ | |
function display(){ | |
$ret = null; | |
foreach($this->totalz as $pool=>$hashrate){ | |
$ret .= ucfirst($pool).' is crunching @ '.number_format($hashrate).' Mh/s'.'<br>'; | |
} | |
return $ret; | |
} | |
/** | |
* Cacluates the queried pools total hash rate and returns string | |
* | |
* @return string | |
*/ | |
function total_rate(){ | |
return 'Total Hash Rate: '.number_format(array_sum($this->totalz)).' Mh/s'; | |
} | |
/** | |
* Querys the total OMC hash rate and returns string | |
* | |
* @return string | |
*/ | |
function total_omc(){ | |
$result = $this->call_api('totalomc'); | |
return 'The total OMC volume is currently: '.number_format(htmlentities($result)).' Mh/s'; | |
} | |
/** | |
* Get current minig pool dificalty | |
* | |
* @return string | |
*/ | |
function total_diff(){ | |
$result = $this->call_api('diff'); | |
return 'The current Omnicoin difficulty is currently: '.number_format(htmlentities($result)).' .'; | |
} | |
} | |
/** | |
* Example: | |
* | |
* Initilise the object and query the API, by passing the pool ids | |
*/ | |
$omc = new omc(); | |
$omc->get_pool_hash('nethash'); | |
$omc->get_pool_hash('OMhash'); | |
$omc->get_pool_hash('BLhash'); | |
$omc->get_pool_hash('MOhash'); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<p><?php echo $omc->display(); ?></p> | |
<p><?php echo $omc->total_rate();?></p> | |
<p><?php echo $omc->total_omc();?></p> | |
<p><?php echo $omc->total_diff();?></p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment