This repository has been archived by the owner on Oct 13, 2019. It is now read-only.
/
p2pool.php
64 lines (48 loc) · 2.06 KB
/
p2pool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require_once('abstract.php');
/*
* @author Stoyvo
*/
class Pools_P2Pool extends Pools_Abstract {
// Pool Information
protected $_addess;
protected $_type = 'p2pool';
// api calls to make
protected $_actions = array(
'current_payouts', // payout of this round
'global_stats',
'local_stats',
'web/currency_info',
);
public function __construct($params) {
parent::__construct($params);
$this->_addess = $params['address'];
$this->_fileHandler = new FileHandler('pools/' . $this->_type . '/'. hash('md4', $params['address']) .'.json');
}
public function update() {
if ($GLOBALS['cached'] == false || $this->_fileHandler->lastTimeModified() >= 30) { // updates every 30 seconds
$poolData = array();
foreach ($this->_actions as $action) {
$poolData[$action] = curlCall($this->_apiURL . '/' . $action);
}
// Offline Check
if (empty($poolData[$this->_actions[0]])) {
return;
}
// Data Order
$data['type'] = $this->_type;
$data['coin'] = $poolData['web/currency_info']['symbol'];
$data['balance'] = number_format($poolData['current_payouts'][$this->_addess], 8);
$data['user_hashrate'] = formatHashrate($poolData['local_stats']['miner_hash_rates'][$this->_addess]/1000);
$data['pool_hashrate'] = formatHashrate($poolData['global_stats']['pool_nonstale_hash_rate']/1000);
$data['pool_uptime'] = formatTimeElapsed($poolData['local_stats']['uptime']);
$data['pool_fee'] = $poolData['local_stats']['fee'] . '%';
$data['peers_in'] = $poolData['local_stats']['peers']['incoming'];
$data['peers_out'] = $poolData['local_stats']['peers']['outgoing'];
$data['url'] = $this->_apiURL;
$this->_fileHandler->write(json_encode($data));
return $data;
}
return json_decode($this->_fileHandler->read(), true);
}
}