|
2 | 2 |
|
3 | 3 | namespace Etherscan\Api;
|
4 | 4 |
|
| 5 | +use Etherscan\APIConf; |
| 6 | +use Etherscan\Exception\ErrorException; |
| 7 | +use Etherscan\Exception\InvalidArgumentException; |
| 8 | + |
5 | 9 | /**
|
6 | 10 | * Class Stats
|
7 | 11 | * @package Etherscan\Api
|
8 | 12 | * @author Maslakou Ihar <igormaslakoff@gmail.com>
|
9 | 13 | */
|
10 | 14 | class Stats extends AbstractApi
|
11 | 15 | {
|
| 16 | + /** |
| 17 | + * Get Total Supply of Ether. |
| 18 | + * Returns the current amount of Ether in circulation. |
| 19 | + * |
| 20 | + * @return array Result returned in Wei, to get value in Ether divide resultAbove / 1000000000000000000 |
| 21 | + * @throws \Etherscan\Exception\ErrorException |
| 22 | + */ |
| 23 | + public function ethSupply() |
| 24 | + { |
| 25 | + return $this->request->exec([ |
| 26 | + 'module' => "stats", |
| 27 | + 'action' => "ethsupply", |
| 28 | + ]); |
| 29 | + } |
| 30 | + /** |
| 31 | + * Get Total Supply of Ether 2 |
| 32 | + * Returns the current amount of Ether in circulation, ETH2 Staking rewards and EIP1559 burnt fees statistics. |
| 33 | + * |
| 34 | + * @return array Result returned in Wei, to get value in Ether divide resultAbove / 1000000000000000000 |
| 35 | + * @throws \Etherscan\Exception\ErrorException |
| 36 | + */ |
| 37 | + public function eth2Supply() |
| 38 | + { |
| 39 | + return $this->request->exec([ |
| 40 | + 'module' => "stats", |
| 41 | + 'action' => "ethsupply2", |
| 42 | + ]); |
| 43 | + } |
12 | 44 |
|
13 | 45 | /**
|
14 |
| - * Get Token TotalSupply by TokenName (Supported TokenNames: DGD, MKR, |
15 |
| - * FirstBlood, HackerGold, ICONOMI, Pluton, REP, SNGLS). |
| 46 | + * Get Ether LastPrice Price. |
| 47 | + * Returns the latest price of 1 ETH. |
16 | 48 | *
|
17 |
| - * or |
| 49 | + * @return array |
| 50 | + * @throws \Etherscan\Exception\ErrorException |
| 51 | + */ |
| 52 | + public function ethPrice() |
| 53 | + { |
| 54 | + return $this->request->exec([ |
| 55 | + 'module' => "stats", |
| 56 | + 'action' => "ethprice", |
| 57 | + ]); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Get Ethereum Nodes Size |
| 62 | + * Returns the size of the Ethereum blockchain, in bytes, over a date range. |
18 | 63 | *
|
19 |
| - * by ContractAddress. |
| 64 | + * @param string $startdate the starting date in yyyy-MM-dd format, eg. 2019-02-01 |
| 65 | + * @param string $enddate the ending date in yyyy-MM-dd format, eg. 2019-02-28 |
| 66 | + * @param string $clienttype the Ethereum node client to use, either geth or parity |
| 67 | + * @param string $syncmode the type of node to run, either default or archive |
| 68 | + * @param string $sort 'asc' or 'desc' |
20 | 69 | *
|
21 |
| - * @param string $tokenIdentifier Token name from the list or contract address. |
| 70 | + * @return array |
| 71 | + * @throws \Etherscan\Exception\ErrorException |
| 72 | + * @throws \Etherscan\Exception\InvalidArgumentException |
| 73 | + */ |
| 74 | + public function getNodesSize($startdate, $enddate, $clienttype, $syncmode, $sort = "asc") |
| 75 | + { |
| 76 | + if (!in_array($clienttype, APIConf::$clientTypes)) { |
| 77 | + throw new InvalidArgumentException("Invalid client type"); |
| 78 | + } |
| 79 | + |
| 80 | + if (!in_array($syncmode, APIConf::$syncModes)) { |
| 81 | + throw new InvalidArgumentException("Invalid sync mode type"); |
| 82 | + } |
| 83 | + |
| 84 | + return $this->request->exec([ |
| 85 | + 'module' => "stats", |
| 86 | + 'action' => "chainsize", |
| 87 | + 'startdate' => $startdate, |
| 88 | + 'enddate' => $enddate, |
| 89 | + 'clienttype' => $clienttype, |
| 90 | + 'syncmode' => $syncmode, |
| 91 | + 'sort' => $sort |
| 92 | + ]); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * Get Total Nodes Count |
| 97 | + * Returns the total number of discoverable Ethereum nodes. |
22 | 98 | *
|
23 | 99 | * @return array
|
24 | 100 | * @throws \Etherscan\Exception\ErrorException
|
25 | 101 | */
|
26 |
| - public function tokenSupply($tokenIdentifier) { |
27 |
| - $params = [ |
| 102 | + public function getNodesCount() |
| 103 | + { |
| 104 | + return $this->request->exec([ |
28 | 105 | 'module' => "stats",
|
29 |
| - 'action' => "tokensupply", |
30 |
| - ]; |
| 106 | + 'action' => "nodecount", |
| 107 | + ]); |
| 108 | + } |
31 | 109 |
|
32 |
| - if (strlen($tokenIdentifier) === 42) { |
33 |
| - $params['contractaddress'] = $tokenIdentifier; |
34 |
| - } else { |
35 |
| - $params['tokenname'] = $tokenIdentifier; |
36 |
| - } |
| 110 | + /** |
| 111 | + * Get Daily Network Transaction Fee |
| 112 | + * Returns the amount of transaction fees paid to miners per day. |
| 113 | + * |
| 114 | + * @param string $startdate the starting date in yyyy-MM-dd format, eg. 2019-02-01 |
| 115 | + * @param string $enddate the ending date in yyyy-MM-dd format, eg. 2019-02-28 |
| 116 | + * @param string $sort 'asc' or 'desc' |
| 117 | + * |
| 118 | + * @return array |
| 119 | + * @throws \Etherscan\Exception\ErrorException |
| 120 | + */ |
| 121 | + public function getDailyTransactionFee($startdate, $enddate, $sort = "asc") |
| 122 | + { |
| 123 | + return $this->request->exec([ |
| 124 | + 'module' => "stats", |
| 125 | + 'action' => "dailytxnfee", |
| 126 | + 'startdate' => $startdate, |
| 127 | + 'enddate' => $enddate, |
| 128 | + 'sort' => $sort |
| 129 | + ]); |
| 130 | + } |
37 | 131 |
|
38 |
| - return $this->request->exec($params); |
| 132 | + /** |
| 133 | + * Get Daily New Address Count |
| 134 | + * Returns the number of new Ethereum addresses created per day. |
| 135 | + * |
| 136 | + * @param string $startdate the starting date in yyyy-MM-dd format, eg. 2019-02-01 |
| 137 | + * @param string $enddate the ending date in yyyy-MM-dd format, eg. 2019-02-28 |
| 138 | + * @param string $sort 'asc' or 'desc' |
| 139 | + * |
| 140 | + * @return array |
| 141 | + * @throws \Etherscan\Exception\ErrorException |
| 142 | + */ |
| 143 | + public function getDailyNewAddressCount($startdate, $enddate, $sort = "asc") |
| 144 | + { |
| 145 | + return $this->request->exec([ |
| 146 | + 'module' => "stats", |
| 147 | + 'action' => "dailynewaddress", |
| 148 | + 'startdate' => $startdate, |
| 149 | + 'enddate' => $enddate, |
| 150 | + 'sort' => $sort |
| 151 | + ]); |
39 | 152 | }
|
40 | 153 |
|
41 | 154 | /**
|
42 |
| - * Get Total Supply of Ether. |
| 155 | + * Get Daily Network Utilization |
| 156 | + * Returns the daily average gas used over gas limit, in percentage. |
43 | 157 | *
|
44 |
| - * @return array Result returned in Wei, to get value in Ether divide resultAbove / 1000000000000000000 |
| 158 | + * @param string $startdate the starting date in yyyy-MM-dd format, eg. 2019-02-01 |
| 159 | + * @param string $enddate the ending date in yyyy-MM-dd format, eg. 2019-02-28 |
| 160 | + * @param string $sort 'asc' or 'desc' |
| 161 | + * |
| 162 | + * @return array |
45 | 163 | * @throws \Etherscan\Exception\ErrorException
|
46 | 164 | */
|
47 |
| - public function ethSupply() { |
| 165 | + public function getDailyNetworkUtilization($startdate, $enddate, $sort = "asc") |
| 166 | + { |
48 | 167 | return $this->request->exec([
|
49 | 168 | 'module' => "stats",
|
50 |
| - 'action' => "ethsupply", |
| 169 | + 'action' => "dailynetutilization", |
| 170 | + 'startdate' => $startdate, |
| 171 | + 'enddate' => $enddate, |
| 172 | + 'sort' => $sort |
51 | 173 | ]);
|
52 | 174 | }
|
53 | 175 |
|
54 | 176 | /**
|
55 |
| - * Get Ether LastPrice Price. |
| 177 | + * Get Daily Average Network Hash Rate |
| 178 | + * Returns the historical measure of processing power of the Ethereum network. |
| 179 | + * |
| 180 | + * @param string $startdate the starting date in yyyy-MM-dd format, eg. 2019-02-01 |
| 181 | + * @param string $enddate the ending date in yyyy-MM-dd format, eg. 2019-02-28 |
| 182 | + * @param string $sort 'asc' or 'desc' |
56 | 183 | *
|
57 | 184 | * @return array
|
58 | 185 | * @throws \Etherscan\Exception\ErrorException
|
59 | 186 | */
|
60 |
| - public function ethPrice() { |
| 187 | + public function getDailyAverageHashRate($startdate, $enddate, $sort = "asc") |
| 188 | + { |
61 | 189 | return $this->request->exec([
|
62 | 190 | 'module' => "stats",
|
63 |
| - 'action' => "ethprice", |
| 191 | + 'action' => "dailyavghashrate", |
| 192 | + 'startdate' => $startdate, |
| 193 | + 'enddate' => $enddate, |
| 194 | + 'sort' => $sort |
| 195 | + ]); |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * Get Daily Transaction Count |
| 200 | + * Returns the number of transactions performed on the Ethereum blockchain per day. |
| 201 | + * |
| 202 | + * @param string $startdate the starting date in yyyy-MM-dd format, eg. 2019-02-01 |
| 203 | + * @param string $enddate the ending date in yyyy-MM-dd format, eg. 2019-02-28 |
| 204 | + * @param string $sort 'asc' or 'desc' |
| 205 | + * |
| 206 | + * @return array |
| 207 | + * @throws \Etherscan\Exception\ErrorException |
| 208 | + */ |
| 209 | + public function getDailyTransactionCount($startdate, $enddate, $sort = "asc") |
| 210 | + { |
| 211 | + return $this->request->exec([ |
| 212 | + 'module' => "stats", |
| 213 | + 'action' => "dailytx", |
| 214 | + 'startdate' => $startdate, |
| 215 | + 'enddate' => $enddate, |
| 216 | + 'sort' => $sort |
| 217 | + ]); |
| 218 | + } |
| 219 | + |
| 220 | + /** |
| 221 | + * Get Daily Average Network Difficulty |
| 222 | + * Returns the historical mining difficulty of the Ethereum network. |
| 223 | + * |
| 224 | + * @param string $startdate the starting date in yyyy-MM-dd format, eg. 2019-02-01 |
| 225 | + * @param string $enddate the ending date in yyyy-MM-dd format, eg. 2019-02-28 |
| 226 | + * @param string $sort 'asc' or 'desc' |
| 227 | + * |
| 228 | + * @return array |
| 229 | + * @throws \Etherscan\Exception\ErrorException |
| 230 | + */ |
| 231 | + public function getDailyAverageNetworkDifficulty($startdate, $enddate, $sort = "asc") |
| 232 | + { |
| 233 | + return $this->request->exec([ |
| 234 | + 'module' => "stats", |
| 235 | + 'action' => "dailyavgnetdifficulty", |
| 236 | + 'startdate' => $startdate, |
| 237 | + 'enddate' => $enddate, |
| 238 | + 'sort' => $sort |
| 239 | + ]); |
| 240 | + } |
| 241 | + |
| 242 | + /** |
| 243 | + * Get Ether Historical Daily Market Cap |
| 244 | + * Returns the historical Ether daily market capitalization. |
| 245 | + * |
| 246 | + * @param string $startdate the starting date in yyyy-MM-dd format, eg. 2019-02-01 |
| 247 | + * @param string $enddate the ending date in yyyy-MM-dd format, eg. 2019-02-28 |
| 248 | + * @param string $sort 'asc' or 'desc' |
| 249 | + * |
| 250 | + * @return array |
| 251 | + * @throws \Etherscan\Exception\ErrorException |
| 252 | + */ |
| 253 | + public function getDailyMarketCap($startdate, $enddate, $sort = "asc") |
| 254 | + { |
| 255 | + return $this->request->exec([ |
| 256 | + 'module' => "stats", |
| 257 | + 'action' => "ethdailymarketcap", |
| 258 | + 'startdate' => $startdate, |
| 259 | + 'enddate' => $enddate, |
| 260 | + 'sort' => $sort |
| 261 | + ]); |
| 262 | + } |
| 263 | + |
| 264 | + /** |
| 265 | + * Get Ether Historical Price |
| 266 | + * Returns the historical price of 1 ETH. |
| 267 | + * |
| 268 | + * @param string $startdate the starting date in yyyy-MM-dd format, eg. 2019-02-01 |
| 269 | + * @param string $enddate the ending date in yyyy-MM-dd format, eg. 2019-02-28 |
| 270 | + * @param string $sort 'asc' or 'desc' |
| 271 | + * |
| 272 | + * @return array |
| 273 | + * @throws \Etherscan\Exception\ErrorException |
| 274 | + */ |
| 275 | + public function getHistoricalPrice($startdate, $enddate, $sort = "asc") |
| 276 | + { |
| 277 | + return $this->request->exec([ |
| 278 | + 'module' => "stats", |
| 279 | + 'action' => "ethdailyprice", |
| 280 | + 'startdate' => $startdate, |
| 281 | + 'enddate' => $enddate, |
| 282 | + 'sort' => $sort |
64 | 283 | ]);
|
65 | 284 | }
|
66 |
| -} |
| 285 | + |
| 286 | + /** |
| 287 | + * Get Token TotalSupply by TokenName (Supported TokenNames: DGD, MKR, |
| 288 | + * FirstBlood, HackerGold, ICONOMI, Pluton, REP, SNGLS). |
| 289 | + * |
| 290 | + * or |
| 291 | + * |
| 292 | + * by ContractAddress. |
| 293 | + * |
| 294 | + * @param string $tokenIdentifier Token name from the list or contract address. |
| 295 | + * |
| 296 | + * @return array |
| 297 | + * @throws \Etherscan\Exception\ErrorException |
| 298 | + */ |
| 299 | + public function tokenSupply($tokenIdentifier) |
| 300 | + { |
| 301 | + $params = [ |
| 302 | + 'module' => "stats", |
| 303 | + 'action' => "tokensupply", |
| 304 | + ]; |
| 305 | + |
| 306 | + if (strlen($tokenIdentifier) === 42) { |
| 307 | + $params['contractaddress'] = $tokenIdentifier; |
| 308 | + } else { |
| 309 | + $params['tokenname'] = $tokenIdentifier; |
| 310 | + } |
| 311 | + |
| 312 | + return $this->request->exec($params); |
| 313 | + } |
| 314 | +} |
0 commit comments