-
Notifications
You must be signed in to change notification settings - Fork 1
/
status.js
1036 lines (939 loc) · 30.8 KB
/
status.js
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Utility for checking the various dependencies of https://teia.art
*/
const axios = require('axios')
const axiosRetry = require('axios-retry')
// Need NFT_STORAGE_KEY env variable
require('dotenv').config()
const {
Octokit
} = require("@octokit/rest")
// Need GITHUB_TOKEN env variable
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
userAgent: 'teia status',
})
const GRAPHQL_ENDPOINT = 'https://teztok.teia.art/v1/graphql'
const TEZOS_ADDRESS_REGEX = `^(tz1|tz2|tz3|KT1)[0-9a-zA-Z]{33}$`
const BLOCKCHAIN_LEVEL_DIFF = 70 // arbitrary blockchain level comparison
const BLOCKCHAIN_TIME_DIFF_MINS = 10 // arbitrary blockchain time comparison
const HTTP_OK = 200
axiosRetry(axios, {
retries: 5,
retryDelay: (retryCount) => {
console.log('retryDelay', retryCount)
return retryCount * 5000
},
retryCondition: (error) => {
if (error && error.response) {
console.log('retryCondition', error.response.status, error.config.url)
return axiosRetry.isNetworkOrIdempotentRequestError(error) || error.response.status === 429
}
return axiosRetry.isNetworkOrIdempotentRequestError(error)
}
})
const logAxiosError = (error) => {
try {
if (error) {
if (error.response && error.response.statusText) {
console.error(error.response.status, error.response.statusText, error.config.url)
} else if (error.isAxiosError) {
console.error(error.message)
} else {
console.error(error)
}
}
} catch (err) {
console.error(error)
}
}
const downloadList = async (url) => {
try {
let res = await axios.get(url)
return res.data
} catch (error) {
logAxiosError(error)
}
return null
}
const validTezosAccount = (account) => {
const match = account.trim().match(TEZOS_ADDRESS_REGEX)
if (match) {
return match.length > 0
} else {
return false
}
}
const getDipdupHead = `query {
dipdup_head {
created_at
hash
level
name
timestamp
updated_at
}
}`
const getDipdupHeadStatus = `query {
dipdup_head_status {
name
status
}
}`
const OBJKT_TOKEN_QUERY = `query getTokenAsks($tokenId: String!, $fa2: String!) {
token(where: {token_id: {_eq: $tokenId}, fa_contract: {_eq: $fa2}}) {
creators {
creator_address
}
royalties {
receiver_address
amount
decimals
}
listings(order_by: {price: asc}, where: {price: {_gt: 0}, _or: [{status: {_eq: "active"}, currency_id: {_eq: 1}, seller: {owner_operators: {token: {fa_contract: {_eq: $fa2}, token_id: {_eq: $tokenId}}, allowed: {_eq: true}}, held_tokens: {quantity: {_gt: "0"}, token: {fa_contract: {_eq: $fa2}, token_id: {_eq: $tokenId}}}}}, {status: {_eq: "active"}}]}) {
id
amount
amount_left
price
seller_address
shares
seller {
alias
address
}
}
}
}`
const TEZTOK_LEVEL_QUERY = `query MyQuery {
events_aggregate {
aggregate {
max {
level
}
}
}
}`
const TEZTOK_METADATA_PROCESSED_QUERY = `query MyQuery {
tokens(limit: 20, order_by: {minted_at: desc_nulls_last}) {
metadata_status
token_id
minted_at
}
}`
const fetchGraphQL = async (operationsDoc, operationName, variables, endpoint) => {
let result = null
try {
const response = await axios.post(endpoint ? endpoint : GRAPHQL_ENDPOINT, {
query: operationsDoc,
variables: variables,
operationName: operationName,
})
if (response.data.errors) {
console.error(response.data.errors)
result = null
} else {
result = response.data
}
} catch (error) {
if (error.response && error.response.statusText) {
console.error(error.response.status, error.response.statusText, error.config.url)
} else {
logAxiosError(error)
}
}
if (result) {
return result
}
return {
errors: 'fetchGraphQL failed'
}
}
const TZKT_API_ONLINE = 'TzKT API is online.'
const TZKT_API_DOWN = '**TzKT API is down.**'
const TZKT_TIMEOUT = 30000
let tzktApiHead = null
let tzktApiStatusMessage = TZKT_API_ONLINE
const checkTzktStatus = async () => {
try {
const tzktResponse = await axios({
method: 'get',
url: 'https://api.tzkt.io/v1/head',
timeout: TZKT_TIMEOUT
})
if (!tzktResponse) {
tzktApiStatusMessage = TZKT_API_DOWN
return
}
tzktApiHead = tzktResponse.data
const apiResponse = await axios({
method: 'get',
url: 'https://api.tzkt.io/v1/accounts/tz1XtjZTzEM6EQ3TnUPUQviCD6WfcsZRHXbj/balance',
timeout: TZKT_TIMEOUT
})
if (!apiResponse) {
tzktApiStatusMessage = TZKT_API_DOWN
return
}
tzktApiStatusMessage = TZKT_API_ONLINE
} catch (error) {
if (error) {
if (error.response && error.response.statusText) {
console.error('checkTzktStatus', error.response.status, error.response.statusText, error.config.url)
} else {
logAxiosError(error)
}
}
tzktApiStatusMessage = TZKT_API_DOWN
}
}
const TEIA_INDEXER_UP_TO_DATE = `Teia legacy indexer is up to date.`
const TEIA_INDEXER_ERROR = '**Teia legacy indexer is experiencing technical difficulties.**'
let indexerStatusMessage = TEIA_INDEXER_UP_TO_DATE
const checkIndexerStatus = async () => {
if (tzktApiHead) {
try {
const diff = Math.abs(tzktApiHead.knownLevel - tzktApiHead.level)
if (diff > BLOCKCHAIN_LEVEL_DIFF) {
indexerStatusMessage = `Teia legacy indexer problem: TzKT API is ${diff} blocks behind.`
return
}
const dipdupHeadStatus = await fetchGraphQL(getDipdupHeadStatus)
const tzktNode = dipdupHeadStatus.data.dipdup_head_status.find(({ status }) => status === 'OK')
if (!tzktNode) {
indexerStatusMessage = '**Unknown Teia legacy indexer head status.**'
return
}
const dipdupState = await fetchGraphQL(getDipdupHead)
const mainnetNode = dipdupState.data.dipdup_head.find(({ name }) => name === tzktNode.name)
if (!mainnetNode) {
indexerStatusMessage = TEIA_INDEXER_ERROR
return
}
if (tzktApiHead && mainnetNode) {
const delta = Math.abs(tzktApiHead.level - mainnetNode.level)
if (delta > BLOCKCHAIN_LEVEL_DIFF) {
indexerStatusMessage = `**Teia legacy indexer is currently delayed by ${delta} blocks. During this period, operations (mint, collect, swap) are prone to fail.**`
} else {
indexerStatusMessage = TEIA_INDEXER_UP_TO_DATE
}
} else {
indexerStatusMessage = TEIA_INDEXER_ERROR
}
} catch (error) {
console.error(error)
indexerStatusMessage = TEIA_INDEXER_ERROR
}
}
}
const fetchJSON = async (url) => {
try {
const response = await axios({
method: 'get',
url,
timeout: 1000 * 60 * 2
})
return response.data
} catch (error) {
logAxiosError(error)
}
return null
}
const TEIA_TZKT_SERVER_UP_TO_DATE = `Teia TzKT server is up to date.`
const TEAI_TZKT_SERVER_ERROR = '**Teia TzKT server is experiencing technical difficulties.**'
let teiaTzktStatusMessage = TEIA_TZKT_SERVER_UP_TO_DATE
const checkTeiaTzktIndexerStatus = async () => {
if (tzktApiHead) {
try {
const teztokHead = await fetchJSON(
`https://tzkt.teia.rocks/v1/head`
)
if (tzktApiHead && teztokHead) {
const delta = Math.abs(tzktApiHead.level - teztokHead.level)
if (delta > BLOCKCHAIN_LEVEL_DIFF) {
teiaTzktStatusMessage = `**Teia TzKT server is currently delayed by ${delta} blocks. During this period, operations (mint, collect, swap) are prone to fail.**`
} else {
teiaTzktStatusMessage = TEIA_TZKT_SERVER_UP_TO_DATE
}
} else {
teiaTzktStatusMessage = TEAI_TZKT_SERVER_ERROR
}
} catch (error) {
console.error(error)
teiaTzktStatusMessage = TEAI_TZKT_SERVER_ERROR
}
}
}
const TEZTOK_ONLINE = `Teia TezTok indexer is online.`
const TEZTOK_ERROR = '**Teia TezTok indexer is experiencing technical difficulties.**'
const TEZTOK_GRAPHQL_SERVER = 'https://teztok.teia.art/v1/graphql'
let teztokIndexerStatusMessage = TEZTOK_ONLINE
const diffTime = (targetDateString) => {
const nowUTC = new Date().toISOString()
const now = new Date(nowUTC)
const targetDate = new Date(targetDateString)
const timeDiffMillis = targetDate.getTime() - now.getTime()
const timeDiffMinutes = Math.floor(timeDiffMillis / (1000 * 60))
return timeDiffMinutes
}
const checkTeztokIndexerStatus = async () => {
try {
const response = await fetchGraphQL(TEZTOK_LEVEL_QUERY, 'MyQuery', {}, TEZTOK_GRAPHQL_SERVER)
if (response && response.data && response.data.events_aggregate) {
teztokIndexerStatusMessage = TEZTOK_ONLINE
if (tzktApiHead) {
const delta = Math.abs(tzktApiHead.level - response.data.events_aggregate.aggregate.max.level)
if (delta > BLOCKCHAIN_LEVEL_DIFF) {
teztokIndexerStatusMessage = `**Teia TezTok indexer is currently delayed by ${delta} blocks. During this period, operations (mint, collect, swap) are prone to fail.**`
} else {
teztokIndexerStatusMessage = `Teia TezTok indexer is up to date.`
const mediaSTatusResponse = await fetchGraphQL(TEZTOK_METADATA_PROCESSED_QUERY, 'MyQuery', {}, TEZTOK_GRAPHQL_SERVER)
if (mediaSTatusResponse && mediaSTatusResponse.data && mediaSTatusResponse.data.tokens) {
let errors = 0
let unprocessed = 0
let delayed = 0
for (let index = 0; index < mediaSTatusResponse.data.tokens.length; index++) {
const token = mediaSTatusResponse.data.tokens[index]
if (token.metadata_status === 'error') {
errors++
}
if (token.metadata_status === 'unprocessed') {
unprocessed++
if (diffTime(token.minted_at) <= -10) {
delayed++
}
}
}
if (errors > 1) {
teztokIndexerStatusMessage = `**Teia TezTok indexer metadata processing errors.**`
} else if (delayed >= 1) {
teztokIndexerStatusMessage = `**Teia TezTok indexer metadata processing behind schedule.**`
} else if (unprocessed > 1) {
teztokIndexerStatusMessage = `**Teia TezTok indexer metadata processing delayed.**`
}
}
}
} else {
teztokIndexerStatusMessage = TEZTOK_ERROR
}
} else {
teztokIndexerStatusMessage = `**Teia TezTok indexer is offline.**`
}
} catch (error) {
console.error(error)
teztokIndexerStatusMessage = TEZTOK_ERROR
}
}
const OBJKT_INDEXER_ONLINE = `Objkt.com indexer is online.`
let objkIndexerStatusMessage = OBJKT_INDEXER_ONLINE
const checkObjktIndexerStatus = async () => {
try {
const response = await fetchGraphQL(OBJKT_TOKEN_QUERY, 'getTokenAsks', { tokenId: '768380', fa2: 'KT1RJ6PbjHpwc3M5rw5s2Nbmefwbuwbdxton' }, 'https://data.objkt.com/v3/graphql')
if (response && response.data && response.data.token) {
objkIndexerStatusMessage = OBJKT_INDEXER_ONLINE
} else {
objkIndexerStatusMessage = `**Objkt.com indexer is offline.**`
}
} catch (error) {
console.error(error)
objkIndexerStatusMessage = '**Objkt.com indexer is experiencing technical difficulties.**'
}
}
const IPFS_GATEWAY_RESPONSIVE = `IPFS gateway (nftstorage.link) is responsive.`
let ipfsGatewayImageMessage = IPFS_GATEWAY_RESPONSIVE
const checkIpfsGateway = async () => {
// We check if the gateway is up by loading 1x1 px image
// Same as: https://ipfs.github.io/public-gateway-checker/
try {
const start = Date.now()
const url = 'https://nftstorage.link/ipfs/bafybeibwzifw52ttrkqlikfzext5akxu7lz4xiwjgwzmqcpdzmp3n5vnbe'
await new Promise(async (resolve, reject) => {
const timer = setTimeout(() => {
reject(new Error(`Timeout when attempting to load '${url}`))
}, 15000)
try {
const response = await axios.get(url, {
responseType: 'arraybuffer',
})
const buffer = Buffer.from(response.data, 'base64')
clearTimeout(timer)
if (buffer) {
resolve()
} else {
reject(new Error(`Could not download '${url}`))
}
} catch (error) {
clearTimeout(timer)
if (error == null) {
reject(new Error(`Unknown error when attempting to load '${url}`))
} else {
reject(error)
}
}
})
const millis = Date.now() - start
if (millis < 5000) {
ipfsGatewayImageMessage = IPFS_GATEWAY_RESPONSIVE
return true
} else {
ipfsGatewayImageMessage = `**IPFS gateway (nftstorage.link) is slow.**`
return false
}
} catch (error) {
logAxiosError(error)
ipfsGatewayImageMessage = '**IPFS gateway (nftstorage.link) is experiencing technical difficulties.**'
}
return false
}
const TEIA_ONLINE = 'Teia.art is online.'
let teiaStatusMessage = TEIA_ONLINE
const TEIA_COMMIT_LATEST = 'Teia.art has the latest GitHub commit.'
let teiaCommitStatusMessage = TEIA_COMMIT_LATEST
let commitUpToDate = true
const checkGui = async () => {
try {
let res = await axios.get('https://teia.art', { timeout: 10000 })
const data = res.data
if (data.indexOf('<head>') != -1) {
teiaStatusMessage = TEIA_ONLINE
}
let found = false
let sha
const result = await axios.head('https://teia.art')
if (result.status === HTTP_OK) {
sha = result.headers['x-teia-commit-hash']
}
if (!sha) {
const regex = /<meta name="build-commit" content="([a-z0-9]*)"/i
found = data.match(regex)
if (found.length > 1) {
sha = found[1]
}
}
if (sha) {
const res = await octokit.request(`GET https://api.github.com/repos/teia-community/teia-ui/commits/main`, {})
if (res && res.data.sha === sha) {
teiaCommitStatusMessage = TEIA_COMMIT_LATEST
} else {
teiaCommitStatusMessage = '**Teia.art is behind the latest GitHub commit.**'
}
}
} catch (error) {
logAxiosError(error)
teiaStatusMessage = '**Teia.art is offline.**'
}
}
let nftStorageStatus = 'NFT.Storage is operational.'
const checkNftStorage = async () => {
try {
let res = await axios.get('https://status.nft.storage/')
const data = res.data
const regexIncident = /unresolved-incidents/i
const foundIncident = data.match(regexIncident)
if (foundIncident && foundIncident.length >= 1) {
nftStorageStatus = `**NFT.Storage is experiencing an incident.**`
return
} else {
const regexStatus = /data-component-status="([a-z_]*)"/i
const foundStatus = data.match(regexStatus)
if (foundStatus && foundStatus.length > 1) {
if (foundStatus[1] === 'operational') {
nftStorageStatus = `NFT.Storage is operational.`
} else {
nftStorageStatus = `**NFT.Storage is experiencing an outage.**`
return
}
} else {
nftStorageStatus = `**NFT.Storage status is unknown.**`
return
}
}
} catch (error) {
logAxiosError(error)
nftStorageStatus = `**NFT.Storage status is unknown.**`
return
}
try {
let result = await axios({
method: 'get',
url: 'https://api.nft.storage/bafkreidivzimqfqtoqxkrpge6bjyhlvxqs3rhe73owtmdulaxr5do5in7u',
headers: { 'Authorization': 'Bearer ' + process.env.NFT_STORAGE_KEY }
})
if (result.data.ok) {
nftStorageStatus = `NFT.Storage is operational.`
} else {
nftStorageStatus = `**NFT.Storage is experiencing an outage.**`
}
} catch (error) {
logAxiosError(error)
nftStorageStatus = `**NFT.Storage is experiencing an outage.**`
}
}
let latestObjtId = 701552
const LATEST_ID_QUERY = `query LatestFeed {
token: tokens(
where: {artifact_uri: {_neq: ""}}
order_by: {minted_at: desc}
limit: 1
) {
id: token_id
}
}`
const getLastestId = async () => {
try {
let response = await fetchGraphQL(LATEST_ID_QUERY, 'LatestFeed', {})
latestObjtId = parseInt(response.data.token[0].id)
} catch (error) {
console.error(error)
}
return latestObjtId
}
let swapHistoryCount = 0
const SWAP_HISTORY_QUERY = `query swapHistory($timestamp: timestamptz!) {
swap: events(
where: {type: {_in: ["TEIA_SWAP"]}, timestamp: {_gte: $timestamp}}
order_by: {timestamp: desc}
) {
token {
id: token_id
}
}
}`
const getSwapHistory = async () => {
try {
var date = new Date()
date.setDate(date.getDate() - 1)
const timestamp = date.toISOString().slice(0, -5) + '+00:00'
let response = await fetchGraphQL(SWAP_HISTORY_QUERY, 'swapHistory', { timestamp })
swapHistoryCount = response.data.swap.length
} catch (error) {
console.error(error)
}
return swapHistoryCount
}
let mintHistoryCount = 0
const MINT_HISTORY_QUERY = `query mintHistory($timestamp: timestamptz!) {
token: tokens(
where: {artifact_uri: {_neq: ""}, minted_at: {_gte: $timestamp}}
order_by: {minted_at: desc}
) {
id: token_id
}
}`
const getMintHistory = async () => {
try {
var date = new Date()
date.setDate(date.getDate() - 1)
const timestamp = date.toISOString().slice(0, -5) + '+00:00'
let response = await fetchGraphQL(MINT_HISTORY_QUERY, 'mintHistory', { timestamp })
mintHistoryCount = response.data.token.length
} catch (error) {
console.error(error)
}
return mintHistoryCount
}
let tzProfilesMessage = 'TzProfiles is online.'
const DIPDUP_HEAD = `{
dipdup_head {
name
level
timestamp
}
}`
const checkTzProfiles = async () => {
try {
const dipdupState = await fetchGraphQL(DIPDUP_HEAD, null, null, 'https://indexer.tzprofiles.com/v1/graphql')
const timestamp = Date.parse(dipdupState.data.dipdup_head[0].timestamp)
const now = new Date()
const diffTime = Math.abs(now - timestamp)
const diffMins = Math.ceil(diffTime / (1000 * 60))
let diffLevel = 0
if (tzktApiHead) {
diffLevel = tzktApiHead.knownLevel - dipdupState.data.dipdup_head[0].level
}
if (diffLevel > BLOCKCHAIN_LEVEL_DIFF) {
tzProfilesMessage = `**TzProfiles indexer is ${diffLevel} blocks behind.**`
return
} else if (diffMins > BLOCKCHAIN_TIME_DIFF_MINS) {
tzProfilesMessage = `**TzProfiles indexer is ${diffMins} mins behind.**`
return
}
let res = await axios.get('https://api.tzprofiles.com/tz1XtjZTzEM6EQ3TnUPUQviCD6WfcsZRHXbj')
if (res.data.length > 0) {
tzProfilesMessage = 'TzProfiles is online.'
} else {
tzProfilesMessage = '**TzProfiles is down.**'
}
} catch (error) {
if (error.response && error.response.statusText) {
console.error(error.response.status, error.response.statusText, error.config.url)
} else {
logAxiosError(error)
}
tzProfilesMessage = '**TzProfiles is down.**'
}
return tzProfilesMessage
}
const MEMPOOL_QUERY = `{
transactions(where: {destination: {_eq: "KT1PHubm9HtyQEJ4BBpMTVomq6mhbfNZ9z5w"}, status: {_neq: "in_chain"}, network: {_eq: "mainnet"}}, limit: 100, order_by: {created_at: desc}) {
amount
target: destination
parameter: parameters
branch
created_at
errors
hash
type: kind
signature
status
counter
bakerFee: fee
gasLimit: gas_limit
sender: source
storageLimit: storage_limit
}
}`
const MEMPOOL_MESSAGE_NOMINAL = 'Nominal number of transactions in the blockchain mempool.'
let mempoolMessage = MEMPOOL_MESSAGE_NOMINAL
const checkMempool = async () => {
// https://dipdup.net/sandbox.html?service=mempool
try {
const mempoolList = await fetchGraphQL(MEMPOOL_QUERY, null, null, 'https://mempool.dipdup.net/v1/graphql')
const transactions = mempoolList.data.transactions
if (transactions.length > 10) {
mempoolMessage = '**High number of transactions in the blockchain mempool.**'
return mempoolMessage
}
mempoolMessage = MEMPOOL_MESSAGE_NOMINAL
} catch (error) {
console.error(error)
mempoolMessage = '**Mempool status unknown.**'
}
return mempoolMessage
}
const RESTRICTED_LIST_WELL_FORMATTED = 'Restricted list is well-formatted.'
let restrictedListMessage = RESTRICTED_LIST_WELL_FORMATTED
let restrictedNumber = 0
const checkRestrictedList = async () => {
try {
let restrictedList = await downloadList(
'https://raw.githubusercontent.com/teia-community/teia-report/main/restricted.json'
)
if (restrictedList) {
if (!Array.isArray(restrictedList)) {
restrictedListMessage = '**Restricted list is not formatted correctly.**'
} else {
for (let index = 0; index < restrictedList.length; index++) {
const address = restrictedList[index]
if (!validTezosAccount(address)) {
restrictedListMessage = `**Restricted list contains an invalid address: ${address}.**`
return
}
}
restrictedNumber = restrictedList.length
restrictedListMessage = RESTRICTED_LIST_WELL_FORMATTED
}
}
} catch (error) {
console.error(error)
restrictedListMessage = '**Restricted list could not be retrieved.**'
estrictedNumber = 0
}
}
let nsfwNumber = 0
const checkNSFWList = async () => {
try {
let nsfwList = await downloadList(
'https://raw.githubusercontent.com/teia-community/teia-report/main/nsfw.json'
)
if (nsfwList) {
nsfwNumber = nsfwList.length
}
} catch (error) {
console.error(error)
nsfwNumber = 0
}
}
let photosensitiveNumber = 0
const checkPhotosensitiveList = async () => {
try {
let photosensitiveList = await downloadList(
'https://raw.githubusercontent.com/teia-community/teia-report/main/photosensitive.json'
)
if (photosensitiveList) {
photosensitiveNumber = photosensitiveList.length
}
} catch (error) {
console.error(error)
photosensitiveNumber = 0
}
}
const rpcNodes = []
let checkingRpc = false
const CANNOT_DETERMINE_RPC_RESULTS = '**Unknown RPC nodes status**'
let rpcNodesMessage = 'RPC nodes status pending.'
// List from: https://github.com/versumstudios/rpc-health/blob/main/cron/rpc.js
const checkRpcNodes = async () => {
if (checkingRpc) {
return
}
checkingRpc = true
const RPC_NODES = [
'mainnet.api.tez.ie',
'mainnet.smartpy.io',
'rpc.tzbeta.net',
'mainnet.tezos.marigold.dev',
'rpc.tzkt.io/mainnet',
'mainnet.teia.rocks',
//'eu01-node.teztools.net'
]
try {
if (tzktApiHead) {
for (let index = 0; index < RPC_NODES.length; index++) {
const node = RPC_NODES[index]
let level = -1
let time = 0
const before = Date.now()
await axios
.get(`https://${node}/chains/main/blocks/head/header`, { timeout: 10000 })
.then((response) => {
const data = response.data
level = Math.abs(tzktApiHead.level - data.level)
time = Date.now() - before
const found = rpcNodes.find((e) => e.node === node)
if (found) {
found.level = level
found.time = time
found.status = response.status
found.error = false
} else {
rpcNodes.push({ level, time, node, status: response.status, error: false })
}
})
.catch((error) => {
console.error('error', node)
if (error.response) {
console.error(error.response.data)
console.error(error.response.status)
console.error(error.response.headers)
} else {
console.error(error)
}
const found = rpcNodes.find((e) => e.node === node)
if (found) {
found.error = true
} else {
rpcNodes.push({ node, error: true })
}
})
}
rpcNodesMessage = `RPC nodes status:`
for (let index = 0; index < rpcNodes.length; index++) {
const node = rpcNodes[index]
if (node.error) {
rpcNodesMessage += `\n • **${node.node}: Unknown**`
} else {
if (node.status === HTTP_OK) {
if (node.level > BLOCKCHAIN_LEVEL_DIFF) {
rpcNodesMessage += `\n • **${node.node}: Delayed by ${node.level} blocks**`
} else if (Math.ceil(node.time / (1000 * 60)) > BLOCKCHAIN_TIME_DIFF_MINS) {
rpcNodesMessage += `\n • **${node.time}: Delayed by ${node.time} milliseconds**`
} else {
rpcNodesMessage += `\n • ${node.node}: OK`
}
} else {
rpcNodesMessage += `\n • **${node.node}: level=${node.level} time=${node.time}, status=${node.status}**`
}
}
}
}
} catch (error) {
if (error.response && error.response.statusText) {
console.error(error.response.status, error.response.statusText, error.config.url)
} else {
logAxiosError(error)
}
rpcNodesMessage = CANNOT_DETERMINE_RPC_RESULTS
}
checkingRpc = false
}
const CANNOT_DETERMINE_VOTING_RESULTS = '**Unknown Teia Token Distribution Voting results**'
let daoTokenDistributionVoteMessage = CANNOT_DETERMINE_VOTING_RESULTS
const POLL_ID = 'QmeJ9ATjn4ge9phDzvpmdZzRZdRoKJdyk4swPiVgaxAx6z'
const checkDaoTokenDistributionVotes = async () => {
try {
let teiaUsersList = await downloadList('https://cache.teia.rocks/ipfs/QmNihShvZkXq7aoSSH3Nt1VeLjgGkESr3LoCzShNyV4uzp')
if (teiaUsersList) {
if (!Array.isArray(teiaUsersList)) {
daoTokenDistributionVoteMessage = '**Teia user list is not formatted correctly.**'
} else {
let pollInformation = await downloadList(`https://cache.teia.rocks/ipfs/${POLL_ID}`)
if (pollInformation["multi"] == "false") {
pollInformation["opt1"] = "YES"
pollInformation["opt2"] = "NO"
}
let allVotes = await downloadList(`https://api.mainnet.tzkt.io/v1/bigmaps/64367/keys?limit=10000&key.string=${POLL_ID}`)
let votes = []
for (let index = 0; index < allVotes.length; index++) {
const vote = allVotes[index]
if (teiaUsersList.includes(vote.key.address)) {
votes.push(vote)
}
}
let results = {}
for (let i = 1; i < 4; i++) {
let iString = i.toString()
results[iString] = { "name": pollInformation["opt" + iString], "votes": 0 }
}
for (let index = 0; index < votes.length; index++) {
const vote = votes[index]
results[vote["value"]]["votes"] += 1
}
daoTokenDistributionVoteMessage = `${votes.length} Teia users have voted so far (${allVotes.length - votes.length} votes were invalid):`
const keys = Object.keys(results)
for (const key of keys) {
const entry = results[key]
daoTokenDistributionVoteMessage += `\n- ${entry.name}: ${entry.votes} votes (${(entry.votes * 100 / votes.length).toFixed(1)}%)`
}
}
}
} catch (error) {
console.error(error)
daoTokenDistributionVoteMessage = CANNOT_DETERMINE_VOTING_RESULTS
}
}
const TEIA_IPFS_GATEWAY_RESPONSIVE = `IPFS gateway (cache.teia.rocks) is responsive.`
let teiaIpfsGatewayImageMessage = TEIA_IPFS_GATEWAY_RESPONSIVE
const checkTeiaIpfsGateway = async () => {
// We check if the Teia IPFS gateway is up by loading a text file that contains the word: "ok"
// This url will never be cached and will always hit the ipfs gateway
try {
const start = Date.now()
const url = 'https://cache.teia.rocks/ipfs/Qmf46hrJfcA8TvEMh6VNHM2G4JxsykxfYwcfhRr5ZFT12E'
await new Promise(async (resolve, reject) => {
const timer = setTimeout(() => {
reject(new Error(`Timeout when attempting to load '${url}`))
}, 15000)
try {
const response = await axios.get(url)
clearTimeout(timer)
if (response) {
if (response.data.trim() === 'ok') {
resolve()
} else {
reject(new Error(`Invalid content for '${url}`))
}
} else {
reject(new Error(`Could not download '${url}`))
}
} catch (error) {
clearTimeout(timer)
if (error == null) {
reject(new Error(`Unknown error when attempting to load '${url}`))
} else {
reject(error)
}
}
})
const millis = Date.now() - start
if (millis < 5000) {
teiaIpfsGatewayImageMessage = TEIA_IPFS_GATEWAY_RESPONSIVE
return true
} else {
teiaIpfsGatewayImageMessage = `**IPFS gateway (cache.teia.rocks) is slow.**`
return false
}
} catch (error) {
logAxiosError(error)
teiaIpfsGatewayImageMessage = '**IPFS gateway (cache.teia.rocks) is experiencing technical difficulties.**'
}
return false
}
// Status text using Discord markdown formatting
const getStatus = () => {
return `${teiaStatusMessage}
${teiaCommitStatusMessage}
${teiaTzktStatusMessage}
${teztokIndexerStatusMessage}
${objkIndexerStatusMessage}
${ipfsGatewayImageMessage}
${teiaIpfsGatewayImageMessage}
${nftStorageStatus}
${tzktApiStatusMessage}
${tzProfilesMessage}
${mempoolMessage}
${restrictedListMessage}
${rpcNodesMessage}
Latest mint is OBJKT ${latestObjtId}.
Number of OBJKT mints in the last 24 hours: ${mintHistoryCount}
Number of Teia swaps in the last 24 hours: ${swapHistoryCount}
Content moderation:
\t• ${restrictedNumber} restricted accounts
\t• ${nsfwNumber} NSFW OBJKTs
\t• ${photosensitiveNumber} photosensitive OBJKTs`
}
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
let firstTime = true
let checking = false
let checkingCounter = 0
const startChecking = async () => {
const checkAll = async () => {
try {
if (checkingCounter > 5) {
checkingCounter = 0
checking = false
}
if (!checking) {
checking = true
console.log('Checking status...')
await checkTzktStatus()
await getSwapHistory()
await getMintHistory()
await checkIpfsGateway()
// await checkIndexerStatus()
await checkTeiaTzktIndexerStatus()
await checkTeztokIndexerStatus()
await checkObjktIndexerStatus()
await getLastestId()
await checkGui()
await checkNftStorage()
await checkTzProfiles()
await checkMempool()
await checkRestrictedList()
await checkNSFWList()
await checkPhotosensitiveList()
await checkRpcNodes()
//await checkDaoTokenDistributionVotes()