-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmonSI.js
1586 lines (1378 loc) · 85.9 KB
/
monSI.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
// Sample startBlock or startRound values
//startingBlockNumber = 7745129 // Redistribution contract deployment block
//startingBlockNumber = 7753068 // First Commit transaction on Redistribution contract
//startingBlockNumber = 51029*blocksPerRound // First round to credit the winner
//startingBlockNumber = 51232*blocksPerRound // First round to have a slash
//startingBlockNumber = Math.min(7786054, 7787724, 7786660, 7787122) // My nodes' first rounds
//startingBlockNumber = 51323*blocksPerRound // Recent slash followed by freeze
//startingBlockNumber = 51333*blocksPerRound // Frozen testing
const configs = {
goerli: {
redistributionContract: "0xF4963031E8b9f9659CB6ed35E53c031D76480EAD".toLowerCase(),
stakeRegistryContract: "0x18391158435582D5bE5ac1640ab5E2825F68d3a4".toLowerCase(),
gBZZTokenContract: "0x2aC3c1d3e24b45c6C310534Bc2Dd84B5ed576335".toLowerCase(),
postageStampContract: "0x7aAC0f092F7b961145900839Ed6d54b1980F200c".toLowerCase(),
RedistributionABI: [{"inputs":[{"internalType":"address","name":"staking","type":"address"},{"internalType":"address","name":"postageContract","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_count","type":"uint256"}],"name":"CountCommits","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_count","type":"uint256"}],"name":"CountReveals","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"l","type":"string"}],"name":"Log","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"l","type":"string"},{"indexed":false,"internalType":"bytes32","name":"b","type":"bytes32"}],"name":"LogBytes32","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"hash","type":"bytes32"},{"indexed":false,"internalType":"uint8","name":"depth","type":"uint8"}],"name":"TruthSelected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"uint256","name":"stakeDensity","type":"uint256"},{"internalType":"bytes32","name":"hash","type":"bytes32"},{"internalType":"uint8","name":"depth","type":"uint8"}],"indexed":false,"internalType":"struct Redistribution.Reveal","name":"winner","type":"tuple"}],"name":"WinnerSelected","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PostageContract","outputs":[{"internalType":"contract PostageStamp","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"Stakes","outputs":[{"internalType":"contract StakeRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_obfuscatedHash","type":"bytes32"},{"internalType":"bytes32","name":"_overlay","type":"bytes32"}],"name":"commit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentClaimRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentCommitRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"currentCommits","outputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"bytes32","name":"obfuscatedHash","type":"bytes32"},{"internalType":"bool","name":"revealed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentPhaseClaim","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentPhaseCommit","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentPhaseReveal","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRevealRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"currentReveals","outputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"uint256","name":"stakeDensity","type":"uint256"},{"internalType":"bytes32","name":"hash","type":"bytes32"},{"internalType":"uint8","name":"depth","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRoundAnchor","outputs":[{"internalType":"bytes32","name":"returnVal","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRoundReveals","outputs":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"uint256","name":"stakeDensity","type":"uint256"},{"internalType":"bytes32","name":"hash","type":"bytes32"},{"internalType":"uint8","name":"depth","type":"uint8"}],"internalType":"struct Redistribution.Reveal[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentSeed","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"A","type":"bytes32"},{"internalType":"bytes32","name":"B","type":"bytes32"},{"internalType":"uint8","name":"minimum","type":"uint8"}],"name":"inProximity","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint8","name":"depth","type":"uint8"}],"name":"isParticipatingInUpcomingRound","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_overlay","type":"bytes32"}],"name":"isWinner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextSeed","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_overlay","type":"bytes32"},{"internalType":"uint8","name":"_depth","type":"uint8"},{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes32","name":"_revealNonce","type":"bytes32"}],"name":"reveal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"roundLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"winner","outputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"uint256","name":"stakeDensity","type":"uint256"},{"internalType":"bytes32","name":"hash","type":"bytes32"},{"internalType":"uint8","name":"depth","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_overlay","type":"bytes32"},{"internalType":"uint8","name":"_depth","type":"uint8"},{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes32","name":"revealNonce","type":"bytes32"}],"name":"wrapCommit","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"}],
StakeRegistryABI: [{"inputs":[{"internalType":"address","name":"_bzzToken","type":"address"},{"internalType":"uint64","name":"_NetworkId","type":"uint64"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"slashed","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"time","type":"uint256"}],"name":"StakeFrozen","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"slashed","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"StakeSlashed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"overlay","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"lastUpdatedBlock","type":"uint256"}],"name":"StakeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REDISTRIBUTOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bzzToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"bytes32","name":"nonce","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"time","type":"uint256"}],"name":"freezeDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"}],"name":"lastUpdatedBlockNumberOfOverlay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"}],"name":"ownerOfOverlay","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pot","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"slashDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"}],"name":"stakeOfOverlay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"stakes","outputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"lastUpdatedBlockNumber","type":"uint256"},{"internalType":"bool","name":"isValue","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unPause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"}],"name":"usableStakeOfOverlay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawFromStake","outputs":[],"stateMutability":"nonpayable","type":"function"}],
gBZZTokenABI: [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"amount","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"sender","type":"address"},{"name":"recipient","type":"address"},{"name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"cap","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"},{"name":"amount","type":"uint256"}],"name":"mint","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"amount","type":"uint256"}],"name":"burn","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"},{"name":"amount","type":"uint256"}],"name":"burnFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"account","type":"address"}],"name":"addMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"renounceMinter","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"recipient","type":"address"},{"name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"isMinter","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_name","type":"string"},{"name":"_symbol","type":"string"},{"name":"_decimals","type":"uint8"},{"name":"_cap","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"MinterAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"account","type":"address"}],"name":"MinterRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}],
BlockRate: 12, // Expected rate of blocks from chain (12 for goerli, 5 for gnosis, ?? for mainnet)
blocksPerRound: 152
},
gnosis: {
redistributionContract: "0xF4963031E8b9f9659CB6ed35E53c031D76480EAD".toLowerCase(), // TODO: Make this real
stakeRegistryContract: "0x18391158435582D5bE5ac1640ab5E2825F68d3a4".toLowerCase(), // TODO: Make this real
gBZZTokenContract: "0xdBF3Ea6F5beE45c02255B2c26a16F300502F68da".toLowerCase(),
postageStampContract: "0x6a1A21ECA3aB28BE85C7Ba22b2d6eAE5907c900E".toLowerCase(),
// TODO: Verify these for gnosis
RedistributionABI: [{"inputs":[{"internalType":"address","name":"staking","type":"address"},{"internalType":"address","name":"postageContract","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_count","type":"uint256"}],"name":"CountCommits","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_count","type":"uint256"}],"name":"CountReveals","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"l","type":"string"}],"name":"Log","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"l","type":"string"},{"indexed":false,"internalType":"bytes32","name":"b","type":"bytes32"}],"name":"LogBytes32","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"hash","type":"bytes32"},{"indexed":false,"internalType":"uint8","name":"depth","type":"uint8"}],"name":"TruthSelected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"uint256","name":"stakeDensity","type":"uint256"},{"internalType":"bytes32","name":"hash","type":"bytes32"},{"internalType":"uint8","name":"depth","type":"uint8"}],"indexed":false,"internalType":"struct Redistribution.Reveal","name":"winner","type":"tuple"}],"name":"WinnerSelected","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PostageContract","outputs":[{"internalType":"contract PostageStamp","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"Stakes","outputs":[{"internalType":"contract StakeRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_obfuscatedHash","type":"bytes32"},{"internalType":"bytes32","name":"_overlay","type":"bytes32"}],"name":"commit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"currentClaimRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentCommitRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"currentCommits","outputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"bytes32","name":"obfuscatedHash","type":"bytes32"},{"internalType":"bool","name":"revealed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentPhaseClaim","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentPhaseCommit","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentPhaseReveal","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRevealRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"currentReveals","outputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"uint256","name":"stakeDensity","type":"uint256"},{"internalType":"bytes32","name":"hash","type":"bytes32"},{"internalType":"uint8","name":"depth","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRoundAnchor","outputs":[{"internalType":"bytes32","name":"returnVal","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentRoundReveals","outputs":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"uint256","name":"stakeDensity","type":"uint256"},{"internalType":"bytes32","name":"hash","type":"bytes32"},{"internalType":"uint8","name":"depth","type":"uint8"}],"internalType":"struct Redistribution.Reveal[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentSeed","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"A","type":"bytes32"},{"internalType":"bytes32","name":"B","type":"bytes32"},{"internalType":"uint8","name":"minimum","type":"uint8"}],"name":"inProximity","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint8","name":"depth","type":"uint8"}],"name":"isParticipatingInUpcomingRound","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_overlay","type":"bytes32"}],"name":"isWinner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minimumStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextSeed","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_overlay","type":"bytes32"},{"internalType":"uint8","name":"_depth","type":"uint8"},{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes32","name":"_revealNonce","type":"bytes32"}],"name":"reveal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"roundLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"winner","outputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"uint256","name":"stakeDensity","type":"uint256"},{"internalType":"bytes32","name":"hash","type":"bytes32"},{"internalType":"uint8","name":"depth","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_overlay","type":"bytes32"},{"internalType":"uint8","name":"_depth","type":"uint8"},{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes32","name":"revealNonce","type":"bytes32"}],"name":"wrapCommit","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"}],
StakeRegistryABI: [{"inputs":[{"internalType":"address","name":"_bzzToken","type":"address"},{"internalType":"uint64","name":"_NetworkId","type":"uint64"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"slashed","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"time","type":"uint256"}],"name":"StakeFrozen","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"slashed","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"StakeSlashed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"overlay","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"lastUpdatedBlock","type":"uint256"}],"name":"StakeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REDISTRIBUTOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bzzToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"bytes32","name":"nonce","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"time","type":"uint256"}],"name":"freezeDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"}],"name":"lastUpdatedBlockNumberOfOverlay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"}],"name":"ownerOfOverlay","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pot","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"slashDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"}],"name":"stakeOfOverlay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"stakes","outputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"lastUpdatedBlockNumber","type":"uint256"},{"internalType":"bool","name":"isValue","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unPause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"}],"name":"usableStakeOfOverlay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"overlay","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawFromStake","outputs":[],"stateMutability":"nonpayable","type":"function"}],
gBZZTokenABI: [{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"impl"}],"name":"implementation","inputs":[],"constant":true},{"type":"constructor","stateMutability":"nonpayable","payable":false,"inputs":[{"type":"address","name":"_tokenImage"},{"type":"string","name":"_name"},{"type":"string","name":"_symbol"},{"type":"uint8","name":"_decimals"},{"type":"uint256","name":"_chainId"}]},{"type":"fallback","stateMutability":"payable","payable":true}],
BlockRate: 5, // Expected rate of blocks from chain (12 for goerli, 5 for gnosis, ?? for mainnet)
blocksPerRound: 152 // TODO: Verify this for gnosis
}
}
var config
var preloadRounds = 0 // Startup can take a LONG time if you make this large!
var startingBlockNumber = 0 // Unless overridden by argument below
var startingRound = 0
if (process.argv.length < 3) {
console.error(`Usage: ${process.argv[0]} ${process.argv[1]} rpcURL(websocket) <HighlightOverlays...> <options>`)
console.error('Valid options are:')
console.error(' --preloadRounds N Number of rounds to load before current round')
console.error(' --startBlock N Block number to start loading')
console.error(' --startRound N Round number to start loading; each round is 152 blocks')
console.error('')
console.error(`for example: ${process.argv[0]} ${process.argv[1]} ws://localhost:8545 6a7c4d45064a382fdd6913fcfdf631b9cacd163c02f9207dee219ef63e953e43 0xB7563E747205FA41E3C59ADCEC667AA5D7415A8E1F4A61B35232486FF49F7C7B 828bec0209b77c751b8e41cd1e4004e902db05a8a7323f53ddf3d1d3dbb7f412 --preloadRounds 4`)
process.exit(-1)
}
const rpcURL = process.argv[2]
var highlightOverlays = []
const allColors = ["black","red","green","yellow","blue","magenta","cyan","white"]
const hColor = 'yellow' // The highlight color
for (var i=3; i<process.argv.length; i++)
{
if (process.argv[i] == '--preloadRounds')
preloadRounds = Number(process.argv[++i]) // Startup can take a LONG time if you make this large!
else if (process.argv[i] == '--startBlock')
startingBlockNumber = Number(process.argv[++i])
else if (process.argv[i] == '--startRound')
startingRound = Number(process.argv[++i])
else if (process.argv[i].slice(0,1) == '-') {
console.error('Invalid option ${process.argv[i]}')
process.exit(-1)
}
else
{
var overlay = process.argv[i].toLowerCase()
if (overlay.slice(0,2) != '0x') overlay = '0x'+overlay
if (overlay.length != '0x47d48ff50fcfe118ecadb97d6cefe17397a0eeb554e4112b7a24d14ded8451bc'.length) {
console.error('Invalid overlay ${overlay}')
process.exit(-1)
}
if (!highlightOverlays.includes(overlay)) highlightOverlays[highlightOverlays.length] = overlay
}
}
//import blessed from 'blessed';
const blessed = require('blessed')
function isUndefined(value){
// Obtain `undefined` value that's
// guaranteed to not have been re-assigned
var undefined = void(0);
return value === undefined;
}
function specificLocalTime(when)
{
return when.toLocaleTimeString('en-GB') // en-GB gets a 24hour format, but amazingly local time!
}
function currentLocalTime()
{
return specificLocalTime(new Date())
}
function shortID(id, n)
{
if (typeof(id) != 'string') return id
if (id.substring(0,2) == '0x') id = id.substring(2)
if (id.length <= n*2) return id
return id.substring(0,n)+".."+id.substring(id.length-n)
}
function leftID(id, n)
{
if (typeof(id) != 'string') return id
if (id.substring(0,2) == '0x') id = id.substring(2)
if (id.length <= n) return id
return id.substring(0,n-3)+"..."
}
function shortNum(n,plus)
{
if (typeof(n) != "number") return typeof(n)+'('+n+')'
var negative, result
if (n < 0)
{ negative = true
n = -n
}
//if (n >= 100*1000*1000*1000*1000*1000)
// result = (n/(1000*1000*1000*1000*1000)).toFixed(0)+'q'
//else if (n >= 10*1000*1000*1000*1000*1000)
// result = (n/(1000*1000*1000*1000*1000)).toFixed(1)+'q'
//else if (n >= 1*1000*1000*1000*1000*1000)
// result = (n/(1000*1000*1000*1000*1000)).toFixed(2)+'q'
//else
if (n >= 100*1000*1000*1000*1000)
result = (n/(1000*1000*1000*1000)).toFixed(0)+'t'
else if (n >= 10*1000*1000*1000*1000)
result = (n/(1000*1000*1000*1000)).toFixed(1)+'t'
else if (n >= 1*1000*1000*1000*1000)
result = (n/(1000*1000*1000*1000)).toFixed(2)+'t'
else if (n >= 100*1000*1000*1000)
result = (n/(1000*1000*1000)).toFixed(0)+'b'
else if (n >= 10*1000*1000*1000)
result = (n/(1000*1000*1000)).toFixed(1)+'b'
else if (n >= 1*1000*1000*1000)
result = (n/(1000*1000*1000)).toFixed(2)+'b'
else if (n >= 100*1000*1000)
result = (n/(1000*1000)).toFixed(0)+'m'
else if (n >= 10*1000*1000)
result = (n/(1000*1000)).toFixed(1)+'m'
else if (n >= 1*1000*1000)
result = (n/(1000*1000)).toFixed(2)+'m'
else if (n >= 100*1000)
result = (n/(1000)).toFixed(0)+'k'
else if (n >= 10*1000)
result = (n/(1000)).toFixed(1)+'k'
else if (n >= 1*1000)
result = (n/(1000)).toFixed(2)+'k'
else result = ''+n
if (negative) result = "-"+result
else if (plus) result = "+"+result
return result
}
function wholeBZZ(bzz)
{
while (bzz.length <= 16) {
bzz = '0' + bzz
}
bzz = bzz.slice(0,bzz.length-16)+"."+bzz.slice(bzz.length-16)
while (bzz.slice(-1) == '0') {
bzz = bzz.slice(0,-1)
}
if (bzz.slice(-1) == '.') bzz = bzz + '0'
return bzz
}
function shortBZZ(n,plus) // BZZ token has 16 decimal places, javascript MAX_SAFE_INTEGER = 900719925474099 - strange that ths works!
{
const oneBZZ = 10000000000000000
if (typeof(n) != "number") return typeof(n)+'('+n+')'
var negative, result
if (n < 0)
{ negative = true
n = -n
}
if (n < oneBZZ/100) return shortNum(n,plus)
else if (n >= 100*oneBZZ)
result = (n/(oneBZZ)).toFixed(0)+'bzz'
else if (n >= 10*oneBZZ)
result = (n/(oneBZZ)).toFixed(1)+'bzz'
else if (n >= 1*oneBZZ)
result = (n/(oneBZZ)).toFixed(2)+'bzz'
else
result = (n/(oneBZZ)).toFixed(3)+'bzz'
if (negative) result = "-"+result
else if (plus) result = "+"+result
return result
}
function shortETH(n,plus) // ETH has 18 decimal places, javascript MAX_SAFE_INTEGER = 900719925474099 - strange that this works!
{
const oneETH = 1000000000000000000
if (typeof(n) != "number") return typeof(n)+'('+n+')'
var negative, result
if (n < 0)
{ negative = true
n = -n
}
if (n < oneETH/100) return shortNum(n,plus)
else if (n >= 100*oneETH)
result = (n/(oneETH)).toFixed(0)+'bzz'
else if (n >= 10*oneETH)
result = (n/(oneETH)).toFixed(1)+'bzz'
else if (n >= 1*oneETH)
result = (n/(oneETH)).toFixed(2)+'bzz'
else
result = (n/(oneETH)).toFixed(3)+'bzz'
if (negative) result = "-"+result
else if (plus) result = "+"+result
return result
}
var screen = blessed.screen({
smartCSR: true,
dockBorders : true,
});
screen.title = 'monSI';
// Quit on Escape, q, or Control-C.
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
var boxCount = 0
var boxes = [] // for focus tabbing
var boxFocus = 0
var boxColors = [ 'white', 'blue', 'red', 'green', 'magenta', 'yellow' ]
var boxWidth = 45
screen.key(['tab'], function (ch, key) {
if (boxCount > 0) {
boxes[boxFocus].style.border.fg = 'white'
boxFocus = (boxFocus+1)%boxCount
boxes[boxFocus].style.border.fg = 'green'
screen.render()
}
})
var numWidth = 3 // This is horizontal boxes
var numLines = 10 // This is per box
function createBox(URL)
{
// Create a box for the node
var box = blessed.box({
parent: screen,
mouse: true,
keys: true,
vi: true,
left: (boxCount%numWidth)*boxWidth,
top: Math.trunc(boxCount/numWidth)*(numLines+1),
width: boxWidth+1,
height: (numLines+2),
content: '{center}'+URL+'{/center}',
tags: true,
border: {
type: 'line'
},
style: {
fg: 'brightwhite',
bg: 'black', // Was magenta
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
// Append our box to the screen.
screen.append(box);
// Focus our element.
box.focus();
boxFocus = boxCount // index of focussed box
boxes[boxCount] = box // For later focus tabbing
box.key(['c'], function (ch, key) {
showError(JSON.stringify(ch)+' Got key '+JSON.stringify(key))
})
boxCount = boxCount + 1
return box
}
var playersBox, roundsBox, winnersBox, outputBox, blocksBox
function addBoxes()
{
winnersBox = blessed.box({
title: "Winners",
label: "Winners",
top: 0,
left: '75%',
//left: numWidth*boxWidth,
//width: '100%-'+(numWidth*boxWidth),
width: '25%',
height: '100%',
content: '\n{center}'+rpcURL+'{/center}', // \n\n\nThreshold: '+shortNum(0)+'\nEarly: '+shortNum(10)+'\nTrigger: '+shortNum(100)+'\nBalance {cyan-fg}99%{/cyan-fg}: ~{cyan-fg}'+shortNum((100) * 0.99)+'{/cyan-fg}\nBalance {yellow-fg}98%{/yellow-fg}: ~{yellow-fg}'+shortNum((100) * 0.98)+'{/yellow-fg}',
scrollable: true,
tags: true,
border: {
type: 'line'
},
style: {
fg: 'brightwhite',
bg: 'black', // Was magenta
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
screen.append(winnersBox);
roundsBox = blessed.box({
title: "Rounds",
label: "Rounds",
top: 0,
left: '40%',
width: '35%',
height: '75%',
//content: '\nhh:mm:ss 51316(83) 1-1 1 df6c1b18c... ^2 +7.99t\nhh:mm:ss 51315(83) 4-4 4 828bec020... ^2 +8.04t\nhh:mm:ss 51314(82) 4-4 1+1+1+1=3 179ef3b3b... ^1 +7.89t',
content: '',
scrollable: true,
tags: true,
border: {
type: 'line'
},
style: {
fg: 'brightwhite',
bg: 'black', // Was magenta
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
screen.append(roundsBox);
playersBox = blessed.box({
title: "Players",
label: "Players",
top: 0,
left: 0,
width: '40%',
height: '75%',
//content: '\n22:34:01 51316(83) Player df6c1b18cc21d... claim 2 dc40224af7b1f5fc..a44c5debadc74b75\n22:33:52 51316(45) Player df6c1b18cc21d... reveal 2 dc40224af7b1f5fc..a44c5debadc74b75\n22:33:43 51316(11) Player df6c1b18cc21d... commit 0 5b46e618471c9f32..97ec95dce6876f8a',
content: '',
scrollable: false,
tags: true,
border: {
type: 'line'
},
style: {
fg: 'brightwhite',
bg: 'black', // Was magenta
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
screen.append(playersBox);
blocksBox = blessed.box({
top: '75%',
left: '55%',
width: '20%',
height: '100%',
content: 'hh:mm:ss bbbbbbb nns mmmms',
scrollable: true,
tags: true,
style: {
fg: 'white',
bg: 'black', // Was magenta
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
screen.append(blocksBox);
let colors = 'Colors:'
let brights = 'Brights:'
allColors.forEach(c => {if (c=='black') colors = colors+` {white-bg}{${c}-fg}${c}{/${c}-fg}{/white-bg}`; else colors = colors+` {${c}-fg}${c}{/${c}-fg}`})
allColors.forEach(c => {if (c=='black') brights = brights+` {white-bg}{bright-${c}-fg}${c}{/bright-${c}-fg}{/white-bg}`; else brights = brights+` {bright-${c}-fg}${c}{/bright-${c}-fg}`})
outputBox = blessed.box({
//top: Math.trunc((boxCount+numWidth-1)/numWidth)*(numLines+1)+1,
//left: 0,
//width: numWidth*boxWidth,
//height: '100%',
top: '75%',
left: 0,
width: blocksBox?'55%':'75%',
height: '100%',
content: `{left}error and trace\noutput will appear here\nand scroll down\n{blue-bg}{yellow-fg}yellow{/yellow-fg}{/blue-bg} {blue-bg}white{/blue-bg} {yellow-bg}white{/yellow-bg} {white-bg}{yellow-fg}yellow{/yellow-fg}{/white-bg}\n${colors}\n${brights}{/left}`,
scrollable: true,
tags: true,
style: {
fg: 'white',
bg: 'black', // Was magenta
border: {
fg: '#f0f0f0'
},
hover: {
bg: 'green'
}
}
});
screen.append(outputBox);
}
function setWinnersLineTime(index,when,text) // Caller is expected to trigger the render
{
var line = (isUndefined(when)?' ':specificLocalTime(when)) + ' ' + text
winnersBox.setLine(index, line);
}
function setWinnersLine(index,text)
{
var line = currentLocalTime()+' '+text
winnersBox.setLine(index, line);
screen.render()
}
function addWinnersLine(index,text)
{
var line = currentLocalTime()+' '+text
winnersBox.insertLine(index, line);
screen.render()
}
const debugging = false
var lastErrorTag = ""
function showError(text, tag, time)
{
if (!time) time = new Date()
if (typeof(text) != 'string')
text = JSON.stringify(text, undefined, 2)
var line = specificLocalTime(time)+' '+text
if (debugging) console.error(line)
if (!isUndefined(tag) && tag == lastErrorTag)
{
outputBox.setLine(0, line);
lastErrorTag = tag
} else
{
outputBox.insertLine(0, line);
lastErrorTag = !isUndefined(tag)?tag:""
}
screen.render()
}
const logEnabled = false
function showLog(text)
{
if (typeof(text) != 'string')
text = JSON.stringify(text, undefined, 2)
if (logEnabled) console.error(currentLocalTime()+' '+text)
}
function showLogError(text)
{
if (typeof(text) != 'string')
text = JSON.stringify(text, undefined, 2)
if (!debugging) showLog(text)
showError(text)
}
function colorValue(value, forcePlus, fmtRtn)
{
if (!fmtRtn) fmtRtn = shortNum
if (value < 0)
{ return '{red-fg}'+fmtRtn(value)+'{/red-fg}'
} else if (value > 0)
{ if (isUndefined(forcePlus))
{ return '{green-fg}'+fmtRtn(value)+'{/green-fg}'
}
return '{green-fg}+'+fmtRtn(value)+'{/green-fg}'
}
if (isUndefined(forcePlus))
return '{white-fg}'+fmtRtn(value)+'{/white-fg}'
else return '{white-fg}+'+fmtRtn(value)+'{/white-fg}'
}
function colorSpecificDelta(previousValue, value, forcePlus, fmtRtn)
{
var delta = value - previousValue
if (delta != 0)
{
return ' ('+colorValue(delta, forcePlus, fmtRtn)+')'
}
return ''
}
var lastValues = {}
function clearDelta(name)
{
lastValues[name] = void(0)
}
function valueChanged(name, value)
{
if (isUndefined(lastValues[name])) return true;
return lastValues[name] != value;
}
function colorDelta(name, value, forcePlus, fmtRtn)
{
if (isUndefined(lastValues[name]))
{ lastValues[name] = value
return ''
}
var delta = value - lastValues[name]
lastValues[name] = value;
if (delta != 0)
{
return ' ('+colorValue(delta, forcePlus, fmtRtn)+')'
}
return ''
}
var monitorAddresses = []
function formatAccount(account,n)
{
account = account.toLowerCase()
if (account == config.redistributionContract)
return 'Redistribution'
if (account == config.stakeRegistryContract)
return 'StakeRegistry'
if (account == config.gBZZTokenContract)
return 'gBZZToken'
if (account == config.postageStampContract)
return 'PostageStamp'
var result = leftID(account,n)
var overlay = getAccountOverlay(account)
if (overlay && highlightOverlays.includes(overlay.toLowerCase())) {
result = `{${hColor}-fg}${result}{/${hColor}-fg}`
}
return result
}
function formatOverlay(overlay,n)
{
if (isUndefined(overlay)) {
showLogError(`formatOverlay(${overlay})?`)
return '?undefined?'
}
if (overlay.slice(0,2) != '0x') {
showLogError(`formatOverlay(${overlay})`)
overlay = '0x'+overlay
}
var result = leftID(overlay,n)
if (highlightOverlays.includes(overlay.toLowerCase())) {
result = `{${hColor}-fg}${result}{/${hColor}-fg}`
}
return result
}
function formatAccountPlusOverlay(account,n)
{
if (account.slice(0,2) != '0x') account = '0x'+account
const overlay = getAccountOverlay(account)
if (overlay) return formatAccount(account,n*3/4) + "("+formatOverlay(overlay,n)+")"
else return formatAccount(account,n)
}
var Winners = []
function refreshWinners(winner)
{
if (winner) winner.text = formatWinner(winner)
else Winners.forEach(winner => winner.text = formatWinner(winner))
Winners.sort(function(l,r){
if (l.overlay == r.overlay) return 0
if (l.highlight && !r.highlight) return -1
if (!l.highlight && r.highlight) return 1
if (l.overlay < r.overlay) return -1
if (l.overlay > r.overlay) return 1
})
for (var i=0; i<Winners.length; i++)
{
Winners[i].line = i
setWinnersLineTime(Winners[i].line, Winners[i].when, Winners[i].text)
}
screen.render()
}
function formatWinner(winner)
{
var result = formatOverlay(winner.overlay,12)
if (isPlaying(winner.overlay)) result = '{blue-bg}'+result+'{/blue-bg}'
if (!isUndefined(winner.winCount) && !isUndefined(winner.playCount)) result = result + ` ${winner.winCount}/${winner.playCount}`
if (winner.freezeCount && winner.freezeCount > 0) result = result + ` {cyan-fg}${winner.freezeCount}{/cyan-fg}`
if (winner.slashCount && winner.slashCount > 0) result = result + ` {red-fg}${winner.slashCount}{/red-fg}`
if (winner.amount != 0) result = result + " " + colorValue(winner.amount, false, shortBZZ)+colorDelta(winner.overlay+':amount', winner.amount, true, shortBZZ)
if (winner.frozen) {
if (winner.freezeTarget) result = result + ` {cyan-fg}~${winner.freezeTarget}{/cyan-fg}`
else result = result + " {cyan-fg}FROZEN{/cyan-fg}"
}
return result
}
function getWinner(blockTime, overlay, account)
{
if (!overlay) return undefined
overlay = overlay.toLowerCase()
if (account) account = account.toLowerCase()
for (var i=0; i<Winners.length; i++)
{
if (Winners[i].overlay == overlay) {
if (isUndefined(Winners[i].account)) {
//showLog(`Retro defining overlay ${overlay} account ${account}`)
Winners[i].account = account
if (highlightOverlays.includes(overlay))
monitorAddresses.push(account)
}
if (Winners[i].account == account) {
Winners[i].when = blockTime
Winners[i].frozen = undefined
return Winners[i]
}
}
}
//showLog(`Newly defined overlay ${overlay} account ${account}`)
const winner = {when: blockTime, overlay: overlay, account: account, amount: 0, highlight: highlightOverlays.includes(overlay)}
Winners[Winners.length] = winner
winner.text = formatWinner(Winners[Winners.length-1])
addWinnersLine(Winners.length-1, Winners[Winners.length-1].text)
return Winners[Winners.length-1]
}
function updateWinner(blockTime, overlay, account, amount)
{
if (typeof(amount) == 'string') amount = Number(amount)
const winner = getWinner(blockTime, overlay, account)
if (!winner) return
if (isUndefined(amount)) {
if (!winner.playCount) winner.playCount = 1
else winner.playCount++
if (!winner.winCount) winner.winCount = 0
} else {
winner.amount += amount
if (amount < 0) {
if (!winner.slashCount) winner.slashCount = 1
else winner.slashCount++
}
else if (amount >= 0) {
if (!winner.playCount) winner.playCount = 1
if (!winner.winCount) winner.winCount = 1
else winner.winCount++
}
}
refreshWinners(winner)
}
function freezeWinner(blockTime, overlay, account, blockNumber, time)
{
if (typeof(time) == 'string') time = Number(time)
const winner = getWinner(blockTime, overlay, account)
if (!winner) return
winner.frozen = true
winner.freezeTarget = blockNumber + time + config.blocksPerRound
if (!winner.freezeCount) winner.freezeCount = 1
else winner.freezeCount++
refreshWinners(winner)
}
function getAccountOverlay(account)
{
account = account.toLowerCase()
for (var i=0; i<Winners.length; i++)
{
if (Winners[i].account == account)
return Winners[i].overlay
}
showLog(`Overlay for account ${account} not found`)
return undefined
}
var Rounds = []
//Rounds[Rounds.length] = { when: new Date(), id: block%config.blocksPerRound, commits: 0, reveals: 0, slashes: 0, hashes: [ {hash: "0", count: 1}, {hash: "1", count: 1} ], freezes: 1, reward: 0 }
function formatRound(round)
{
// addRound((PlayersRound+1)*config.blocksPerRound, new Date(), PlayersCommits, PlayersReveals, 0, 0, 0, undefined, undefined, undefined, undefined)
var result = `${round.id}(${round.residual}) ${round.commits}-${round.reveals}`
if (round.slashes > 0) result = result + `={red-fg}${round.slashes}{/red-fg}`
var sameDepth = true
for (var i=0; i<round.hashes.length; i++)
if (round.hashes[i].depth != round.hashes[0].depth)
sameDepth = false
for (var i=0; i<round.hashes.length; i++)
{
if (i>0) result = result + '+'
else result = result + ' '
var term = `${round.hashes[i].count}`
if (!sameDepth) term = term + `^${round.hashes[i].depth}`
if (round.hashes[i].hash == round.truth)
term = `{green-fg}${term}{/green-fg}`
else term = `{red-fg}${term}{/red-fg}`
if (round.hashes[i].highlight
&& (round.hashes.length > 1 || round.hashes[i].count > 1))
term = `{${hColor}-bg}${term}{/${hColor}-bg}`
result = result + term
}
if (round.freezes > 0) result = result + `={cyan-fg}${round.freezes}{/cyan-fg}`
if (round.winner) {
result = result + ` ${formatOverlay(round.winner,12)}`
if (round.depth) result = result + ` ^${round.depth}`
if (!isUndefined(round.reward)) result = result + ' {green-fg}' + shortNum(round.reward,true) + '{/green-fg}'
} else result = result + ' {yellow-fg}UNCLAIMED{/yellow-fg}'
return result
}
function roundFromBlock(blockNumber)
{
return Math.floor(blockNumber/config.blocksPerRound)
}
function roundString(blockNumber)
{
return `${roundFromBlock(blockNumber)}(${blockNumber%config.blocksPerRound})`
}
var LastRoundID = 0
function addRound(blockNumber, blockTime, commits, reveals, slashes, hashes, freezes, truth, depth, reward, winner)
{
const id = roundFromBlock(blockNumber)
if (LastRoundID == id) return // Ignore duplicate end-of-round reports
LastRoundID = id
if (typeof(reward) == 'string') reward = Number(reward)
const round = { when: blockTime, id: id, residual: blockNumber%config.blocksPerRound, commits: commits, reveals: reveals, slashes: slashes, hashes: hashes, freezes: freezes, truth: truth, depth: depth, reward: reward, winner: winner }
//showError(`${formatRound(round)}`)
var line = specificLocalTime(round.when)+' '+formatRound(round)
roundsBox.insertLine(0, line);
screen.render()
}
var Hashes = []
var HashRound = 0
function clearHashes()
{
Hashes = []
}
function addHash(blockNumber, hash, depth, highlight)
{
const round = roundFromBlock(blockNumber)
if (round != HashRound)
clearHashes()
HashRound = round
for (var h=0; h<Hashes.length; h++)
{
if (Hashes[h].hash == hash && Hashes[h].depth == depth) {
Hashes[h].count++
if (highlight) Hashes[h].highlight = highlight
return
}
}
//showError(`${roundString(blockNumber)} new hash ${shortID(hash,16)}`)
Hashes[Hashes.length] = {hash: hash, depth: depth, count: 1, highlight: highlight}
}
var Players = []
var PlayersRound = 0
var PlayersCommits = 0
var PlayersReveals = 0
function clearPlayers()
{
for (var i=0; i<Players.length; i++)
playersBox.setLine(i+1,'')
Players = []
PlayersCommits = 0
PlayersReveals = 0
refreshWinners() // Clear the current player highlights
}
async function updatePlayer(p)
{
const player = Players[p]
var text = `${roundString(player.blockNumber)} ${formatOverlay(player.overlay,12)} ${player.phase}`
if (player.depth) text = text + ` ^${player.depth}`
if (player.hash) text = text + ` ${shortID(player.hash,10)}`
const line = specificLocalTime(player.when)+' '+text
playersBox.setLine(p+1, line);
}
async function flushPreviousRound(blockTime, blockNumber)
{
const round = roundFromBlock(blockNumber)
if (round != PlayersRound) {
if (PlayersRound != 0) {
if (PlayersCommits || PlayersReveals) {
addRound((PlayersRound+1)*config.blocksPerRound-1, blockTime, PlayersCommits, PlayersReveals, 0, Hashes, 0, undefined, undefined, undefined, undefined)
clearHashes()
}
}
clearPlayers()
}
PlayersRound = round
}
async function updatePlayerRound(blockTime, blockNumber)
{
flushPreviousRound(blockTime, blockNumber)
const offset = blockNumber % config.blocksPerRound
var phase
var length
var elapsed
if (offset < config.blocksPerRound / 4) {
phase = 'commit'
length = config.blocksPerRound / 4
elapsed = offset + 1
} else if (offset <= config.blocksPerRound / 2) {
phase = 'reveal'
length = config.blocksPerRound / 4 + 1
elapsed = offset - config.blocksPerRound / 4 + 1
} else {
phase = 'claim'
length = config.blocksPerRound / 2 - 1
elapsed = offset - config.blocksPerRound / 2
}
const remaining = length - elapsed
const percent = Math.floor(elapsed*100/length)
let line = `${specificLocalTime(blockTime)} ${roundString(blockNumber)} ${percent}% of ${phase}, ${remaining} blocks left`
if (config.blocksPerRound-offset-1 != remaining) line = line + `, ${config.blocksPerRound-offset-1} in round`
playersBox.setLine(0, line)
}
function isPlaying(overlay)
{
for (var p=0; p<Players.length; p++)
{
if (Players[p].overlay == overlay)
return true
}
return false
}
async function addPlayer(blockTime, blockNumber, overlay, account, phase, depth, hash)
{
flushPreviousRound(blockTime, blockNumber)
//showLog(`${roundString(blockNumber)} Player ${overlay} ${phase} ${depth} ${shortID(hash,16)}`)
if (phase == 'commit') PlayersCommits++
else if (phase == 'reveal') PlayersReveals++
const player = {when: blockTime, overlay: overlay, blockNumber: blockNumber, phase: phase, depth: depth, hash: hash}
for (var p=0; p<Players.length; p++)
{
if (Players[p].overlay == overlay) {
Players[p] = player
updatePlayer(p)
return true
}
}
Players[Players.length] = player
updatePlayer(Players.length-1)
updateWinner(blockTime, overlay, account, undefined) // new players in the round count as playing, this also highlights current players
return true
}
let Overlays = []
let Accounts = []
async function associateOverlay(blockTime, overlay, account)
{
if (isUndefined(Overlays[account])) {
Overlays[account] = overlay
Accounts[overlay] = account
//showError(`New Account ${account} overlay ${leftID(overlay,18)}`)
}
}
async function handleCommit(blockTime, transaction, receipt, input)
{
if (input.params.length == 2
&& input.params[0].name == '_obfuscatedHash'
&& input.params[1].name == '_overlay'
&& input.params[0].type == 'bytes32'
&& input.params[1].type == 'bytes32') {
associateOverlay(blockTime, input.params[1].value, transaction.from)
return addPlayer(blockTime, receipt.blockNumber, input.params[1].value, transaction.from, "commit", undefined, undefined)
}
return false
}
async function handleReveal(blockTime, transaction, receipt, input)
{
if (input.params.length == 4
&& input.params[0].name == '_overlay'
&& input.params[1].name == '_depth'
&& input.params[2].name == '_hash'
&& input.params[3].name == '_revealNonce'
&& input.params[0].type == 'bytes32'
&& input.params[1].type == 'uint8'