-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.html
274 lines (257 loc) · 9.5 KB
/
widget.html
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'>
<title>TVM-Based networks — current load</title>
<style>
@font-face {
font-family: 'JetBrains Mono';
src: url('https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff2/JetBrainsMono-Regular.woff2') format('woff2'),
url('https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff/JetBrainsMono-Regular.woff') format('woff');
font-weight: 400;
font-style: normal;
font-display: swap;
}
body {
font-family: 'JetBrains Mono', monospace;
margin: 0;
padding: 0;
}
h3 {
margin-bottom: 0;
}
h4 {
margin-top: 0;
margin-bottom: 0;
}
</style>
<script>
const u8 = (value) => BigInt.asUintN(8, BigInt(value)).toString(16)
function metricUpdate(elem) {
let startTime
let totalTransactionCount = 0
let totalBlockCount = 0
const wcCount = {}
return (block) => {
const transactionCount = block.tr_count
const workchainId = u8(block.workchain_id)
wcCount[workchainId] = (wcCount[workchainId] || 0) + transactionCount
const nowTime = Date.now()
if (!startTime) {
startTime = Date.now()
}
totalTransactionCount += transactionCount
totalBlockCount += 1
const timeDiff = nowTime - startTime
const BPS = Number(totalBlockCount / timeDiff * 1000)
const TPS = Number(totalTransactionCount / timeDiff * 1000)
const TPSMC = Number(wcCount['ff'] / timeDiff * 1000)
const TPSMWC0 = Number(wcCount['0'] / timeDiff * 1000)
if (timeDiff > 10000) {
elem.updateElem('bps', `${BPS.toFixed(1)}`)
elem.updateElem('tps', `${TPS.toFixed(1)}`)
if (TPSMC) {
elem.updateElem('tpsMC', `${TPSMC.toFixed(2)}`)
elem.updateElem('tpsWC0', `${TPSMWC0 >= 0 ? TPSMWC0.toFixed(2) : '...'}`)
}
}
}
}
function createMetric(root, network) {
const out = document.createElement('div')
out.className = 'metric'
let extra = ''
if (!network.includes('ackinacki')) {
extra += '<span>(MC: <span data-behavior="tpsMC">...</span></span>'
extra += '<span> WC: <span data-behavior="tpsWC0">...</span>)</span>'
}
out.innerHTML = `<h3>${name(network)}</h3>
<h4>
<span> BPS: <span data-behavior='bps'>...</span><span>
<span> TPS: <span data-behavior='tps'>...</span><span>
${extra}
</h4>
<div data-behavior='output'></div>`
out.updateElem = (name, value) => {
out.querySelector(`[data-behavior=${name}]`).innerHTML = value
}
root.append(out)
return {
up: metricUpdate(out),
log: (message) => out.updateElem('output', message),
}
}
function blockPollingEverX(root, network) {
// TODO implement
console.log(`${network} not implement`)
}
function blockPollingTonCore(root, network) {
// TODO implement
console.log(`${network} not implement`)
}
function blockSubscriptionEverX(root, network) {
const query = 'subscription {blocks {id tr_count workchain_id seq_no shard gen_software_version}}'
const {up, log} = createMetric(root, network)
const connect = (url) => {
const start = Date.now()
let dataCount = 0
let dataEmptyCount = 0
const websocket = new WebSocket(url, [
'graphql-ws',
])
websocket.onopen = function() {
log('Trying to connect...')
websocket.send('{"type":"connection_init","payload":{}}')
websocket.send(`{"id":"1","type":"start","payload":{"variables":{},"extensions":{},"operationName":null,"query":"${query}"}}`)
}
websocket.onclose = function() {
log('Disconnected, reconnect will be attempted in 5 second...')
setTimeout(function() {
connect(url)
}, 5000)
}
websocket.onmessage = function(event) {
const count = 1 / dataEmptyCount * dataCount
const data = JSON.parse(event.data)
if (data.type === 'data') {
dataCount += 1
const block = data.payload.data.blocks
log(logTemplate(network, block))
up(block)
} else {
dataEmptyCount += 1
}
if (count < 1 && Date.now() - start > 10000) {
websocket.close()
}
}
websocket.onerror = function(event) {
log(`<span style='color: red'>ERROR:</span> ${event.data}`)
websocket.close()
}
}
connect(`wss://${graphqlHost(network)}/graphql`)
}
function logTemplate(network, block) {
const url = urlBlock(network, block)
let content = `${block.workchain_id}:${block.shard.slice(0, 2)}:${block.seq_no}`
if (block.gen_software_version) {
content += `|v${block.gen_software_version}`
}
if (url) {
return `<span><a target="_blank" href="${url}">${content}</a></span>`
}
return `<span>${content}</span>`
}
function urlBlock(network, block) {
switch (network) {
case 'shellnet-test':
return `https://shellnet.ackinacki.org/blocks/blockDetails?id=${block.id}`
case 'ackinacki-test':
return `https://ackinacki-testnet.tvmlabs.dev/blocks/blockDetails?id=${block.id}`
case 'ever-main':
return `https://everscan.io/blocks/${block.workchain_id}/${block.shard}/${block.seq_no}`
case 'ever-test':
return `https://testnet.everscan.io/blocks/${block.workchain_id}/${block.shard}/${block.seq_no}`
case 'venom-main':
return `https://venomscan.com/blocks/${block.workchain_id}/${block.shard}/${block.seq_no}`
case 'venom-test':
return `https://testnet.venomscan.com/blocks/${block.workchain_id}/${block.shard}/${block.seq_no}`
case 'gosh-main':
return `https://gosh.live/blocks/blockDetails?id=${block.id}`
case 'gosh-test':
return `https://ackinacki-testnet.tvmlabs.dev/blocks/blockDetails?id=${block.id}`
case 'ever-beta':
return `https://rfld.ever.live/blocks/blockDetails?id=${block.id}`
case 'ever-smft':
return `https://smft.ever.live/blocks/blockDetails?id=${block.id}`
case 'ton-main':
return `https://tonscan.org/block/${block.workchain_id}:${block.shard}:${block.seq_no}`
case 'ton-test':
return `https://testnet.tonscan.org/block/${block.workchain_id}:${block.shard}:${block.seq_no}`
default:
return null
}
}
function graphqlHost(network) {
const projectID = 'a3446bfb5e4e4f2a84d68400a28d990e'
switch (network) {
case 'shellnet-test':
return 'shellnet.ackinacki.org'
case 'ackinacki-test':
return 'ackinacki-testnet.tvmlabs.dev'
case 'gosh-main':
return 'gra01.network.gosh.sh'
case 'venom-main':
return 'venom-mainnet.tvmlabs.dev'
case 'venom-test':
return 'venom-testnet.tvmlabs.dev'
case 'ever-main':
return `mainnet.evercloud.dev/${projectID}`
case 'ever-test':
return `devnet.evercloud.dev/${projectID}`
case 'ton-main':
return 'ton-mainnet.tvmlabs.dev'
case 'ton-test':
return 'ton-testnet.tvmlabs.dev'
default:
return `${network}.evercloud.dev/${projectID}`
}
}
function name(network) {
switch (network) {
case 'shellnet-test':
return 'Acki Nacki Testnet (beta)'
case 'ackinacki-test':
return 'Acki Nacki Testnet (alpha)'
case 'gosh-main':
return 'Gosh Mainnet'
case 'venom-main':
return 'Venom Mainnet'
case 'venom-test':
return 'Venom Testnet'
case 'ever-main':
return 'Everscale Mainnet'
case 'ever-test':
return 'Everscale Testnet'
case 'ton-main':
return 'TON Mainnet'
case 'ton-test':
return 'TON Testnet'
default:
return network
}
}
function loadWidget(elem, network) {
switch (network) {
case 'venom-test':
case 'shellnet-test':
blockPollingEverX(elem, network)
break
case 'ton-main':
case 'ton-test':
blockPollingTonCore(elem, network)
break
default:
blockSubscriptionEverX(elem, network)
}
}
window.addEventListener('load', function () {
const root = document.querySelector('[data-behavior=content]')
loadWidget(root, 'ever-main')
loadWidget(root, 'ever-test')
loadWidget(root, 'venom-main')
loadWidget(root, 'venom-test')
loadWidget(root, 'ton-main')
loadWidget(root, 'ton-test')
loadWidget(root, 'gosh-main')
loadWidget(root, 'ackinacki-test')
loadWidget(root, 'shellnet-test')
})
</script>
</head>
<body>
<h2>Networks current load</h2>
<main data-behavior='content'></main>
</body>
</html>