-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathf2pool.php
More file actions
147 lines (126 loc) · 3.92 KB
/
Copy pathf2pool.php
File metadata and controls
147 lines (126 loc) · 3.92 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
require_once "env.php";
Class F2Pool {
//private $default_api_path = "https://api.f2pool.com/bitcoin/";
private $api_path;
private $username;
private $pool_info;
public function __construct() {
global $ENV;
$this->username = "";
$this->api_path = "";
//$this->api_path = $this->default_api_path;
$this->pool_info = Array();
}
public function getPoolInfo($p) {
if (isset($this->pool_info) && $p != "") {
return $this->pool_info[$p];
//return $this->pool_info[$this->username][$p];
} else {
return NULL;
}
}
public function getApiPath() {
return $this->api_path;
}
public function setApiPath() {
$this->api_path = "https://api.f2pool.com/bitcoin/" . $this->username;
//$this->api_path = "https://api.f2pool.com/bitcoin/" . $this->username . "?multi_account=" . $this->username;
}
public function isApiPathSet() {
return ($this->username != "")
&& ($this->api_path != "");
}
public function setUsername($u) {
$this->username = $u;
$this->setApiPath();
//$this->api_path = $this->default_api_path . $u;
}
public function getUsername() {
if ($this->username) return $this->username;
return "";
}
public function fetchPoolInfo(){
if ($this->isApiPathSet()) {
$this->pool_info = json_decode(file_get_contents($this->getApiPath()), TRUE);
return $this->isValidPoolInfo();
} else {
return NULL;
}
}
private function isValidPoolInfo() {
$result = false;
if (isset($this->pool_info) &&
//isset($this->getPoolInfo("worker_length")) &&
$this->getPoolInfo("worker_length") != "0" &&
$this->getPoolInfo("worker_length") != ""
) {
$result = true;
}
return $result;
}
public function getStatusSummaryMessage() {
return $this->makeStatusSummaryMessage();
}
public function getStatusDetailedMessage() {
$m = $this->makeStatusSummaryMessage();
$m .= $this->makeWorkersDetailMessage();
return $m;
}
public function numOfWorkers() {
if ($this->isValidPoolInfo()) {
return intval($this->getPoolInfo("worker_length"));
} else {
return 0;
}
}
public function numOfOnlineWorkers() {
if ($this->isValidPoolInfo()) {
return intval($this->getPoolInfo("worker_length_online"));
} else {
return 0;
}
}
public function numOfOfflineWorkers() {
return $this->numOfWorkers() - $this->numOfOnlineWorkers();
}
public function getOfflineAlertMessage() {
return $this->makeOfflineAlertMessage();
}
private function makeOfflineAlertMessage() {
$m = $this->numOfOfflineWorkers() . " WORKER(S) OFFLINE";
return $m;
}
private function makeStatusSummaryMessage() {
$m = $this->getPoolInfo("worker_length_online") . "/" . $this->getPoolInfo("worker_length");
$m .= " worker(s) online\n";
$m .= "Total Current Hashrate: " . $this->toTH($this->getPoolInfo("hashrate"),2) . "\n";
$m .= "Total 24h hashrate: " . $this->toTH($this->getPoolInfo("hashes_last_day")/(24*60*60),2) . "\n";
$m .= "Balance: " . $this->toBTC($this->getPoolInfo("fixed_balance")) . "\n";
$m .= "Yesterday's Revenue: " . $this->toBTC($this->getPoolInfo("today_paid")) . "\n";
$m .= "Today's Estimated Revenue: " . $this->toBTC($this->getPoolInfo("value_today")) . "\n";
return $m;
}
private function makeWorkersDetailMessage() {
$m = "\n";
$m .= "Workers:\n";
$counter = 0;
foreach ($this->getPoolInfo("workers") as $worker) {
$counter++;
$m .= $counter . ") " . $worker[0] . " - " . $this->toTH($worker[1],2) . " - ";
$m .= $this->toTH($worker[4]/(24*60*60),2);
}
return $m;
}
private function toTH($h,$d) {
if ($h == "" || floatval($h) == 0) {
return 0;
}
return floor(floatval($h)/10000000000)/100 . " TH/s";
}
private function toBTC($f) {
// takes a string of format 0.123456789123... and returns first 10 chars so it's 0.12345678
return sprintf("%.8f", round($f,8), "0") . " BTC";
}
}
?>