-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
182 lines (163 loc) · 4.83 KB
/
Copy pathfunctions.php
File metadata and controls
182 lines (163 loc) · 4.83 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/* DIVISOR */
function divisor(string $raw, int $decimals): string
{
if (function_exists('bcdiv')) {
$divisor = bcpow('10', (string)$decimals, 0);
$out = bcdiv($raw, $divisor, $decimals);
return rtrim(rtrim($out, '0'), '.');
}
$val = (float)$raw / pow(10, $decimals);
$out = number_format($val, $decimals, '.', '');
return rtrim(rtrim($out, '0'), '.');
}
/* STRING SHORTEN */
function str_shorten(string $str, int $frontLen = 5, int $backLen = 5, string $ellipsis = '...'): string
{
if (mb_strlen($str) <= $frontLen + $backLen) {
return $str;
}
$prefix = mb_substr($str, 0, $frontLen);
$suffix = mb_substr($str, -$backLen);
return $prefix . $ellipsis . $suffix;
}
/* API GET */
function api_get(string $url, int $timeout = 30): array
{
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_FAILONERROR => true,
]);
$response = curl_exec($ch);
if ($response === false) {
$err = curl_error($ch);
curl_close($ch);
return ['error' => $err];
}
curl_close($ch);
return (array)json_decode($response, true);
}
/* BUILD URL */
function build_url(string $base, array $query = []): string
{
return $base . ($query ? '?' . http_build_query($query) : '');
}
/* FRONTIER REWARD */
function frontier_reward(string $address,
string $type = 'pillar',
int $page = 1,
int $per_page = 25): array
{
$url = build_url(
"https://zenonhub.io/api/nom/{$type}/get-frontier-reward-by-page",
[
'address' => $address,
'page' => max(0, $page - 1),
'per_page' => $per_page,
]
);
return api_get($url);
}
/* UNCOLLECTED REWARDS */
function uncollected_rewards(string $address,
string $type = 'pillar'): array
{
$url = build_url(
"https://zenonhub.io/api/nom/{$type}/get-uncollected-reward",
['address' => $address]
);
return api_get($url);
}
/* LIQUIDITY STAKE ENTRIES */
function liquidity_stake_entries(string $address,
int $page_index = 1,
int $page_size = 1000): array
{
$url = build_url(
'https://zenonhub.io/api/nom/liquidity/get-liquidity-stake-entries-by-address',
[
'address' => $address,
'page_index' => max(0, $page_index - 1),
'page_size' => $page_size,
]
);
return api_get($url);
}
/* TOKEN BY ZTS */
function token_by_zts(string $token): array
{
$url = build_url(
'https://zenonhub.io/api/nom/token/get-by-zts',
['token' => $token]
);
return api_get($url);
}
/* UNWRAP TOKEN REQUESTS */
function unwrap_token_requests(string $to_address,
int $page_index = 1,
int $page_size = 1000): array
{
$url = build_url(
'https://zenonhub.io/api/nom/bridge/get-all-unwrap-token-requests-by-to-address',
[
'to_address' => $to_address,
'page_index' => max(0, $page_index - 1),
'page_size' => $page_size,
]
);
return api_get($url);
}
/* ALL UNSIGNED WRAP TOKEN REQUESTS */
function all_unsigned_wrap_token_requests(int $page_index = 1,
int $page_size = 1000): array
{
$url = build_url(
'https://zenonhub.io/api/nom/bridge/get-all-unsigned-wrap-token-requests',
[
'page_index' => max(0, $page_index - 1),
'page_size' => $page_size,
]
);
return api_get($url);
}
/* ALL UNWRAP TOKEN REQUESTS */
function all_unwrap_token_requests(int $page_index = 1,
int $page_size = 1000): array
{
$url = build_url(
'https://zenonhub.io/api/nom/bridge/get-all-unwrap-token-requests',
[
'page_index' => max(0, $page_index - 1),
'page_size' => $page_size,
]
);
return api_get($url);
}
/* MOMENTUMS BY HEIGHT */
function momentums_by_height(int $height = 1,
int $count = 10): array
{
$url = build_url(
'https://zenonhub.io/api/nom/ledger/get-momentums-by-height',
[
'height' => $height,
'count' => $count,
]
);
return api_get($url);
}
/* DETAILED MOMENTUMS BY HEIGHT */
function detailed_momentums_by_height(int $height = 1,
int $count = 10): array
{
$url = build_url(
'https://zenonhub.io/api/nom/ledger/get-detailed-momentums-by-height',
[
'height' => $height,
'count' => $count,
]
);
return api_get($url);
}