php-mpos/public/include/pages/api/getpoolstatus.inc.php
Sebastian Grewe 4ffca7d5ac API overhaul for easier handling of API calls
* [FEATURE] Allow in-class checking for user permissions
* [FEATURE] Allow in-class creation of the JSON data for coherence
* [FEATURE} Added API version in JSON data for client side checks
* [IMPROVEMENT] Adjusted all API calls to use the new JSON layout

**NOTE**: This is breaking backwads compatibility with the old API!
Please adjust your client application to support this new version.
The data array should not change much more other than added features.
2013-09-17 11:55:54 +02:00

68 lines
1.9 KiB
PHP

<?php
// Make sure we are called from index.php
if (!defined('SECURITY')) die('Hacking attempt');
// Check if the API is activated
$api->isActive();
// Check user token
$user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);
// Fetch last block information
$aLastBlock = $block->getLast();
// Efficiency
$aShares = $statistics->getRoundShares();
$aShares['valid'] > 0 ? $dEfficiency = round((100 - (100 / $aShares['valid'] * $aShares['invalid'])), 2) : $dEfficiency = 0;
// Fetch RPC data
if ($bitcoin->can_connect() === true){
$dDifficulty = $bitcoin->getdifficulty();
$iBlock = $bitcoin->getblockcount();
$dNetworkHashrate = $bitcoin->getnetworkhashps();
} else {
$dDifficulty = 1;
$iBlock = 0;
$dNetworkHashrate = 0;
}
// Estimated time to find the next block
$iCurrentPoolHashrate = $statistics->getCurrentHashrate();
// Avoid confusion, ensure our nethash isn't higher than poolhash
if ($iCurrentPoolHashrate > $dNetworkHashrate) $dNetworkHashrate = $iCurrentPoolHashrate;
// Time in seconds, not hours, using modifier in smarty to translate
$iCurrentPoolHashrate > 0 ? $iEstTime = $dDifficulty * pow(2,32) / ($iCurrentPoolHashrate * 1000) : $iEstTime = 0;
$iEstShares = (pow(2, 32 - $config['difficulty']) * $dDifficulty);
// Time since last
$now = new DateTime( "now" );
if (!empty($aLastBlock)) {
$dTimeSinceLast = ($now->getTimestamp() - $aLastBlock['time']);
} else {
$dTimeSinceLast = 0;
}
// Output JSON format
$data = array(
'hashrate' => $iCurrentPoolHashrate,
'efficiency' => $dEfficiency,
'workers' => $worker->getCountAllActiveWorkers(),
'currentnetworkblock' => $iBlock,
'nextnetworkblock' => $iBlock + 1,
'lastblock' => $aLastBlock['height'],
'networkdiff' => $dDifficulty,
'esttime' => $iEstTime,
'estshares' => $iEstShares,
'timesincelast' => $dTimeSinceLast,
'nethashrate' => $dNetworkHashrate
);
echo $api->get_json($data);
// Supress master template
$supress_master = 1;
?>