From 3d942e843445c6772f425c910339a0efd78557dd Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Thu, 4 Jul 2013 13:26:58 +0200 Subject: [PATCH] Adding getpoolstatus API Method Fixes #369 --- .../include/pages/api/getpoolstatus.inc.php | 60 +++++++++++++++++++ .../mmcFE/statistics/pool/authenticated.tpl | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 public/include/pages/api/getpoolstatus.inc.php diff --git a/public/include/pages/api/getpoolstatus.inc.php b/public/include/pages/api/getpoolstatus.inc.php new file mode 100644 index 00000000..ece9f557 --- /dev/null +++ b/public/include/pages/api/getpoolstatus.inc.php @@ -0,0 +1,60 @@ +checkApiKey($_REQUEST['api_key']); + +// 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(); + if (is_array($dDifficulty) && array_key_exists('proof-of-work', $dDifficulty)) + $dDifficulty = $dDifficulty['proof-of-work']; + $iBlock = $bitcoin->getblockcount(); +} else { + $dDifficulty = 1; + $iBlock = 0; +} + +// Estimated time to find the next block +$iCurrentPoolHashrate = $statistics->getCurrentHashrate(); + +// 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 +echo json_encode( + array( + 'getpoolstatus' => array( + 'hashrate' => $iCurrentPoolHashrate, + 'efficiency' => $dEfficiency, + 'workers' => $worker->getCountAllActiveWorkers(), + 'currentnetworkblock' => $iBlock, + 'nextnetworkblock' => $iBlock + 1, + 'lastblock' => $aLastBlock['height'], + 'networkdiff' => $dDifficulty, + 'esttime' => $iEstTime, + 'estshares' => $iEstShares, + 'timesincelast' => $dTimeSinceLast, + ))); + +// Supress master template +$supress_master = 1; +?> diff --git a/public/templates/mmcFE/statistics/pool/authenticated.tpl b/public/templates/mmcFE/statistics/pool/authenticated.tpl index 9d855afa..b85a3926 100644 --- a/public/templates/mmcFE/statistics/pool/authenticated.tpl +++ b/public/templates/mmcFE/statistics/pool/authenticated.tpl @@ -49,7 +49,7 @@ -
  • These stats are also available in JSON format HERE
  • +
  • These stats are also available in JSON format HERE
  • {include file="global/block_footer.tpl"}