-
Notifications
You must be signed in to change notification settings - Fork 33
/
MindMiner.ps1
1042 lines (976 loc) · 39.9 KB
/
MindMiner.ps1
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
<#
MindMiner Copyright (C) 2017-2023 Oleg Samsonov aka Quake4
https://github.com/Quake4/MindMiner
License GPL-3.0
#>
. .\Code\Out-Data.ps1
Out-Iam
Write-Host "Loading ..." -ForegroundColor Green
[bool] $global:HasConfirm = $false
[bool] $global:NeedConfirm = $false
[bool] $global:AskPools = $false
[bool] $global:HasBenchmark = $false
[bool] $global:FChange = $false
[bool] $global:GetQuestionAll = $false
[bool] $global:MRRHour = $false
[array] $global:MRRRentedTypes = @()
$global:MRROffline = @{}
$global:API = [hashtable]::Synchronized(@{})
[bool] $global:Admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
. .\Code\Include.ps1
# ctrl+c hook
[Console]::TreatControlCAsInput = $true
[Console]::Title = "MindMiner $([Config]::Version -replace "v") - $([datetime]::Now.ToString())"
$BinLocation = [IO.Path]::Combine($(Get-Location), [Config]::BinLocation)
New-Item $BinLocation -ItemType Directory -Force | Out-Null
$BinScriptLocation = [scriptblock]::Create("Set-Location('$BinLocation')")
$DownloadJob = $null
[Collections.Generic.List[string]] $DownloadExclude = [Collections.Generic.List[string]]::new()
# download prerequisites
Get-Prerequisites ([Config]::BinLocation)
# read and validate config
$Config = Get-Config
if (!$Config) { exit }
if ($Config.DevicesStatus) {
$Devices = Get-Devices ([Config]::ActiveTypes)
}
elseif ([Config]::ActiveTypes -contains [eMinerType]::CPU) {
$Devices = Get-Devices (@([eMinerType]::CPU))
}
# define cores/threads
if ([Config]::ActiveTypes -contains [eMinerType]::CPU) {
$cpu = $Devices[[eMinerType]::CPU] | Measure-Object Cores, Threads -Sum
[nullable[int]] $threads = $null
if ($Config.DefaultCPUThreads -is [int]) {
$threads = [math]::Min($Config.DefaultCPUThreads, $cpu[1].Sum)
}
[nullable[int]] $cores = $null
if ($Config.DefaultCPUCores -is [int]) {
$cores = [math]::Min($Config.DefaultCPUCores, $cpu[0].Sum)
}
if ($cores -and !$threads) {
$threads = [int][math]::Min($cores * $cpu[1].Sum / $cpu[0].Sum, $cpu[1].Sum)
}
elseif (!$cores -and $threads) {
$cores = [int][math]::Min($threads * $cpu[0].Sum / $cpu[1].Sum, $cpu[0].Sum)
}
if ($threads -and $cores) {
[Config]::DefaultCPU = [CPUConfig]::new($cores, $threads)
}
Remove-Variable threads, cores, cpu
}
[SummaryInfo] $Summary = [SummaryInfo]::new([Config]::RateTimeout, $null -ne $Config.Service)
$Summary.TotalTime.Start()
Clear-Host
Out-Header
$Rates = [Collections.Generic.Dictionary[string, object]]::new()
$ActiveMiners = [Collections.Generic.Dictionary[string, MinerProcess]]::new()
$KnownAlgos = [Collections.Generic.Dictionary[eMinerType, Collections.Generic.Dictionary[string, SpeedProfitInfo]]]::new()
[Config]::ActiveTypes | ForEach-Object {
$KnownAlgos.Add($_, [Collections.Generic.Dictionary[string, SpeedProfitInfo]]::new())
}
[StatCache] $Statistics = [StatCache]::Read([Config]::StatsLocation)
if ($Config.ApiServer) {
if ([Net.HttpListener]::IsSupported) {
if ($global:Admin) {
Write-Host "Starting API server at port $([Config]::ApiPort) for Remote access ..." -ForegroundColor Green
}
else {
Write-Host "Starting API server at port $([Config]::ApiPort) for Local access ..." -ForegroundColor Green
Write-Host "To start API server for remote access run MindMiner as Administrator." -ForegroundColor Yellow
}
Start-ApiServer
}
else {
Write-Host "Http listner not supported. Can't start API server." -ForegroundColor Red
}
}
if ($global:API.Running) {
$global:API.Worker = $Config.WorkerName
$global:API.Config = ($Config.Web($global:Admin) | ConvertTo-Html -Fragment).Replace("<tr><th>*</th></tr>", "<tr><th>Region</th></tr>")
$global:API.Wallets = $Config.Api() | ConvertTo-Json
}
# FastLoop - variable for benchmark or miner errors - very fast switching to other miner - without ask pools and miners
[bool] $FastLoop = $false
# exit - var for exit
[bool] $exit = $false
# main loop
while ($true)
{
if ($Summary.RateTime.IsRunning -eq $false -or $Summary.RateTime.Elapsed.TotalSeconds -ge [Config]::RateTimeout.TotalSeconds) {
$exit = Update-Miner
if ($exit -eq $true) {
$FastLoop = $true
}
else {
$Rates = Get-RateInfo
if ($Summary.RateTime.IsRunning) {
$global:MRRHour = $true
}
}
$Summary.RateTime.Reset()
$Summary.RateTime.Start()
}
elseif (!$Rates -or $Rates.Count -eq 0) {
$Rates = Get-RateInfo
}
if (!$FastLoop) {
# read algorithm mapping
$AllAlgos = [BaseConfig]::ReadOrCreate("algorithms.txt", @{
EnabledAlgorithms = $null
DisabledAlgorithms = $null
Difficulty = $null
RunBefore = $null
RunAfter = $null
})
# how to map algorithms
$AllAlgos.Add("Mapping", [ordered]@{
"0x10" = "Chainox"
"aeternity" = "CuckooCycle"
"argon2d250" = "Argon2-crds"
"argon2d-crds" = "Argon2-crds"
"argon2d500" = "Argon2-dyn"
"argon2d-dyn" = "Argon2-dyn"
"argon2d" = "Argon2-dyn"
"argon2d_dynamic" = "Argon2-dyn"
"argon2d16000" = "Argon2d16K"
"argon2d_16000" = "Argon2d16K"
"autolykosv2" = "Autolykos2"
"autolykos" = "Autolykos2"
"beamhash" = "Beam"
"beamhashII" = "BeamV2"
"beamhash2" = "BeamV2"
"beamhashIII" = "BeamV3"
"beamhash3" = "BeamV3"
"beamv2" = "BeamV2"
"beamv3" = "BeamV3"
"binarium_hash_v1" = "Binarium-V1"
"blakecoin" = "Blake"
"blake256r8" = "Blake"
"blake2b-btcc" = "Blake2b"
"bl2bsha3" = "Handshake"
"blake2bsha3" = "Handshake"
"blake2skadena" = "Kadena"
"blake3" = "Alph"
"blake3aleph" = "Alph"
"blake3_alephium" = "Alph"
"aleph" = "Alph"
"alephium" = "Alph"
"blake3_ironfish" = "Ironfish"
"blake3ironfish" = "Ironfish"
"blake3-iron" = "Ironfish"
"blake3_decred" = "Decred"
"hns" = "Handshake"
"trtl_chukwa" = "Chukwa"
"trtl_chukwa2" = "Chukwa2"
"argon2/chukwa" = "Chukwa"
"argon2/chukwav2" = "Chukwa2"
"argon2dchukwa" = "Chukwa"
"argon2id_chukwa" = "Chukwa"
"argon2id_chukwa2" = "Chukwa2"
"chukwav2" = "Chukwa2"
"chukwa2" = "Chukwa2"
"randomkeva" = "RandomKeva"
"randomx_keva" = "RandomKeva"
"rx/keva" = "RandomKeva"
"randomarq" = "RandomARQ"
"randomx_arqma" = "RandomARQ"
"randomsfx" = "RandomSFX"
"randomx_safex" = "RandomSFX"
"randomv" = "RandomV"
"randomx" = "RandomX"
"RandomXmonero" = "RandomX"
"rx/0" = "RandomX"
"rx/arq" = "RandomARQ"
"rxdag" = "XDagger"
"rx/xdag" = "XDagger"
"xdagger" = "XDagger"
"rx/sfx" = "RandomSFX"
"rx/v" = "RandomV"
"cryptonotewow" = "RandomWOW"
"rx/wow" = "RandomWOW"
"randomwow" = "RandomWOW"
"randomx_wow" = "RandomWOW"
"cryptonightrxl" = "RandomXL"
"rx/loki" = "RandomXL"
"randomx_loki" = "RandomXL"
"randomxl" = "RandomXL"
"cn/superfast" = "cnSFast"
"cryptonight_superfast" = "cnSFast"
"cryptonotefh" = "cnSFast"
"cryptonight_v8_reversewaltz" = "cnRWltz"
"cryptonightrw" = "cnRWltz"
"cryptonight_rw" = "cnRWltz"
"cn/rwz" = "cnRWltz"
"cryptonight_v8_double" = "cnXCash"
"cryptonotev8d" = "cnXCash"
"cn/double" = "cnXCash"
"cn/r" = "CryptonightR"
"cn/gpu" = "cnGPU"
"cngpu" = "cnGPU"
"cnheavy" = "cnHeavy"
"cn_saber" = "cnSaber"
"cnsaber" = "cnSaber"
"cn-heavy/tube" = "cnSaber"
"cryptonoteh" = "cnHeavy"
"cryptonight_haven" = "cnHaven"
"cryptonight_xhv" = "cnHaven"
"cryptonote_haven" = "cnHaven"
"cryptonotehaven" = "cnHaven"
"cn_haven" = "cnHaven"
"cnhaven" = "cnHaven"
"cn-heavy/xhv" = "cnHaven"
"cryptonight_v8_zelerius" = "cnZls"
"cryptonotev8zls" = "cnZls"
"cnzls" = "cnZls"
"cn/zls" = "cnZls"
"cryptonightupx" = "cnUpx"
"cryptonight_upx" = "cnUpx2"
"cryptonightupx2" = "cnUpx2"
"cnupx" = "cnUpx2"
"cnupx2" = "cnUpx2"
"cn/upx2" = "cnUpx2"
"cnv8_upx2" = "cnUpx2"
"cryptonotextl" = "cnFastV2"
"cnfast2" = "cnFastV2"
"cryptonight_fast" = "cnFastV2"
"cn/half" = "cnFastV2"
"cryptonight_masari" = "cnFast"
"cryptonotefast" = "cnFast"
"cn/fast" = "cnFast"
"cnfast" = "cnFast"
"cn/ccx" = "cnConceal"
"cn_conceal" = "cnConceal"
"cnconceal" = "cnConceal"
"cryptonotec" = "cnConceal"
"cryptonight_conceal" = "cnConceal"
"cryptonight_talleo" = "cnTalleo"
"cryptonightulv2" = "cnTalleo"
"cryptonighttlo" = "cnTalleo"
"cn-pico/tlo" = "cnTalleo"
"cntlo" = "cnTalleo"
"cryptonoteturtlev2" = "cnTurtle"
"cryptonight_turtle" = "cnTurtle"
"cnturtle" = "cnTurtle"
"cn-pico" = "cnTurtle"
"cnv7" = "Cryptonightv7"
"cnv8" = "Cryptonightv8"
"cnr" = "CryptonightR"
"cryptonotegpu" = "cnGPU"
"cryptonoter" = "CryptonightR"
"cryptonotev7" = "Cryptonightv7"
"cryptonotev8" = "Cryptonightv8"
"cryptonight_hvy" = "cnHeavy"
"cryptonight_gpu" = "cnGPU"
"cryptonight_heavy" = "cnHeavy"
"cryptonight_heavyx" = "cnHeavy"
"cryptonight_lite_v7" = "Cryptolightv7"
"cryptonight-monero" = "CryptonightR"
"cryptonight_v7" = "Cryptonightv7"
"cryptonight_v8" = "Cryptonightv8"
"cryptonight_r" = "CryptonightR"
"cryptonight_saber" = "cnSaber"
"cryptonightr" = "CryptonightR"
"cryptonightheavy" = "cnHeavy"
"cryptonightheavysaber" = "cnSaber"
"conflux" = "Octopus"
"cuckoo_ae" = "CuckooCycle"
"cuckooaeternity" = "CuckooCycle"
"cuckoocycle" = "CuckooCycle"
"cuckoocycleo" = "Grin29"
"cuckoocycle29swap" = "Swap"
"cuckoocycle31" = "Grin31"
"cuckaroo_swap" = "Swap"
"cuckaroo29s" = "Swap"
"cuckoo24" = "Cuckaroo24"
"cuckaroom29_qitmeer" = "Qitmeer"
"cuckaroo" = "Grin29"
"cuckaroo29" = "Grin29"
"cuckarood" = "Grind29"
"cuckaroo29bfc" = "Bfc"
"cuckaroo29d" = "Grind29"
"cuckaroo29m" = "Cuckaroom"
"cuckarood29" = "Grind29"
"cuckarood29_grin" = "Grind29"
"cuckaroom29" = "Cuckaroom"
"cuckaroo29z" = "Cuckarooz"
"cuckarooz29" = "Cuckarooz"
"cuckatoo" = "Grin31"
"cuckatoo31" = "Grin31"
"cuckatoo31_grin" = "Grin31"
"cuckatoo32" = "Grin32"
"cuckoocycle32" = "Grin32"
"curve" = "Curvehash"
"dynexsolve" = "Dynex"
"Grin" = "Grin29"
"GrinCuckaroo29" = "Grin29"
"GrinCuckarood29" = "Grind29"
"GrinCuckatoo31" = "Grin31"
"GrinCuckatoo32" = "Grin32"
"dagger" = "Ethash"
"daggerhashimoto" = "Ethash"
"jackpot" = "JHA"
"hashimotos" = "Ethash"
"equihash1254" = "Equihash125"
"equihash125_4" = "Equihash125"
"equihash144_5" = "Equihash144"
"equihash1505" = "BeamV3"
"equihash1505g" = "Grimm"
"equihash192_7" = "Equihash192"
"equihash1927" = "Equihash192"
"aion" = "Equihash210"
"equihash210_9" = "Equihash210"
"equihash2109" = "Equihash210"
"equihash96_5" = "Equihash96"
"Equihash-BTG" = "EquihashBTG"
"equihashBTG" = "EquihashBTG"
"Equihash-ZCL" = "Equihash192"
"equihashZCL" = "Equihash192"
"ergo" = "Autolykos2"
"ethereum" = "Ethash"
"ethereum-classic" = "Ethash"
"firo" = "Firopow"
"gr" = "Ghostrider"
"glt-astralhash" = "Astralhash"
"glt-globalhash" = "Globalhash"
"glt-jeonghash" = "Jeonghash"
"glt-padihash" = "Padihash"
"glt-pawelhash" = "Pawelhash"
"kas" = "Kaspa"
"kHeavyHash" = "Kaspa"
"karlsenhash" = "Karlsen"
"karlsenhashnxl" = "Karlsen"
"lyra2rev2" = "Lyra2re2"
"lyra2r2" = "Lyra2re2"
"lyra2v2" = "Lyra2re2"
"lyra2v2-old" = "Lyra2re2"
"lyra2rev3" = "Lyra2v3"
"lyra2re3" = "Lyra2v3"
"lyra2r3" = "Lyra2v3"
# "monero" = "Cryptonightv7"
"m7m" = "M7M"
"m7mv2" = "M7M"
"mgroestl" = "MyrGr"
"minotaurx" = "MinotaurX"
"myriad-groestl" = "MyrGr"
"myriadgroestl" = "MyrGr"
"myr-gr" = "MyrGr"
"neoscrypt" = "NeoScrypt"
"neoscrypt-xaya" = "nsXaya"
"neoscryptxaya" = "nsXaya"
"nexa" = "Nexapow"
"novo" = "Sha256dt"
"phi1612" = "Phi"
"poly" = "Polytimos"
"progpowere" = "ProgpowEre"
"progpow-ethercore" = "ProgpowEre"
"progpowveil" = "ProgpowVeil"
"progpow-veil" = "ProgpowVeil"
"progpow_veil" = "ProgpowVeil"
"progpow_zano" = "ProgpowZano"
"progpowz" = "ProgpowZano"
"progpow-sero" = "ProgpowSero"
"progpow_sero" = "ProgpowSero"
"sero" = "ProgpowSero"
"pyrinhash" = "Pyrin"
"randomgrft" = "Graft"
"randomgraft" = "Graft"
"rx/graft" = "Graft"
"randomyada" = "RandomYada"
"rx/yada" = "RandomYada"
"raven" = "Kawpow"
"rvn" = "Kawpow"
"rethereum" = "Ethashb3"
"rfv2" = "RainForest2"
"scryptn2" = "ScryptN2"
"nscryptv" = "ScryptN2"
"sha3" = "Keccak"
"rad" = "Sha512256d"
"radiant" = "Sha512256d"
"sha512_256d" = "Sha512256d"
"sha512_256d_radiant" = "Sha512256d"
"sib" = "X11Gost"
"sibcoin" = "X11Gost"
"sibcoin-mod" = "X11Gost"
"skeincoin" = "Skein"
"skunkhash" = "Skunk"
"timetravel10" = "Bitcore"
"ubqhash" = "Ubiqhash"
"vit" = "Vitalium"
"verus" = "Verushash"
"x11gost" = "X11Gost"
"x11evo" = "X11Evo"
"x13bcd" = "Bcd"
"x13sm3" = "Hsr"
"x16rtgin" = "X16rt"
"yespower2b" = "Power2b"
"zelhash" = "Equihash125"
"zhash" = "Equihash144"
})
# disable asic algorithms
$AllAlgos.Add("Disabled", @("bcd", "beam", "bitcore", "blake", "blake2b", "blake2s", "handshake", "kadena", "sha256", "sha256asicboost", "sha256-ld", "scrypt", "scrypt-ld", "tensority", "x11", "x11-ld", "x13", "x14", "x15", "quark", "qubit", "myrgr", "lbry", "decred", "sia", "blake", "nist5", "cryptonight", "cryptonightr", "cryptonightv7", "cryptonightv8", "x11gost", "groestl", "eaglesong", "equihash", "lyra2re2", "lyra2z", "pascal", "keccak", "keccakc", "skein", "c11", "timetravel", "skunk"))
# ask needed pools
if ($global:AskPools -eq $true) {
$AllPools = Get-PoolInfo ([Config]::PoolsLocation)
$global:AskPools = $false
}
Write-Host "Pool(s) request ..." -ForegroundColor Green
$AllPools = Get-PoolInfo ([Config]::PoolsLocation)
# check pool exists
if (!$AllPools -or $AllPools.Length -eq 0) {
Write-Host "No Pools!" -ForegroundColor Red
Get-Confirm
continue
}
Write-Host "Miners request ..." -ForegroundColor Green
$AllMiners = Get-ChildItem ([Config]::MinersLocation) | Where-Object Extension -eq ".ps1" | ForEach-Object {
Invoke-Expression "$([Config]::MinersLocation)\$($_.Name)"
}
# filter by exists hardware
$AllMiners = $AllMiners | Where-Object { [Config]::ActiveTypes -contains ($_.Type -as [eMinerType]) }
# download miner
if ($DownloadJob -and $DownloadJob.State -ne "Running") {
$DownloadJob | Remove-Job -Force | Out-Null
$DownloadJob.Dispose()
$DownloadJob = $null
$PathUri | Foreach-Object { $DownloadExclude.Add($_.Path) | Out-Null }
}
$DownloadMiners = $AllMiners | Where-Object { !$_.Exists([Config]::BinLocation) -and $DownloadExclude -notcontains $_.Path } | Select-Object Name, Path, URI, Pass -Unique
if ($DownloadMiners -and ($DownloadMiners.Length -gt 0 -or $DownloadMiners -is [PSCustomObject])) {
Write-Host "Download miner(s): $(($DownloadMiners | Select-Object Name -Unique | ForEach-Object { $_.Name }) -Join `", `") ... " -ForegroundColor Green
if (!$DownloadJob) {
$PathUri = $DownloadMiners | Select-Object Path, URI, Pass -Unique;
$DownloadJob = Start-Job -ArgumentList $PathUri -FilePath ".\Code\Downloader.ps1" -InitializationScript $BinScriptLocation
}
}
# check exists miners & update bench timeout by global value
$AllMiners = $AllMiners | Where-Object { $_.Exists([Config]::BinLocation) } | ForEach-Object {
if ($Config.BenchmarkSeconds -and $Config.BenchmarkSeconds."$($_.Type)" -gt $_.BenchmarkSeconds) {
$_.BenchmarkSeconds = $Config.BenchmarkSeconds."$($_.Type)"
}
[MinerInfo][MinerProfitInfo]::CopyMinerInfo($_, $Config)
}
if ($AllMiners.Length -eq 0) {
Write-Host "No Miners!" -ForegroundColor Red
Get-Confirm
continue
}
# save speed active miners
$ActiveMiners.Values | Where-Object { $_.State -eq [eState]::Running -and $_.Action -eq [eAction]::Normal } | ForEach-Object {
$speed = $_.GetSpeed($false)
if ($speed -gt 0) {
$speed = $Statistics.SetValue($_.Miner.GetFilename(), $_.Miner.GetKey(), $speed, $Config.AverageHashSpeed, 0.25)
if (![string]::IsNullOrWhiteSpace($_.Miner.DualAlgorithm)) {
$speed = $_.GetSpeed($true)
if ($speed -gt 0) {
$speed = $Statistics.SetValue($_.Miner.GetFilename(), $_.Miner.GetKey($true), $speed, $Config.AverageHashSpeed, 0.25)
}
}
}
elseif ($speed -eq 0 -and $_.CurrentTime.Elapsed.TotalSeconds -ge ($_.Miner.BenchmarkSeconds * $(if ($_.Miner.Priority -ge [Priority]::Solo) { 5 } else { 2 }))) {
# no hasrate stop miner and move to nohashe state while not ended
$_.Stop($AllAlgos.RunAfter)
}
}
$KnownAlgos.Values | ForEach-Object { $_.Clear() }
[Config]::SoloParty.Clear()
}
# get devices status
if ($Config.DevicesStatus -and !$FastLoop) {
$Devices = Get-Devices ([Config]::ActiveTypes) $Devices
# power draw save
if (Get-ElectricityPriceCurrency) {
$Benchs = $ActiveMiners.Values | Where-Object { $_.State -eq [eState]::Running -and ($_.CurrentTime.Elapsed.TotalSeconds * 2) -ge $_.Miner.BenchmarkSeconds } | ForEach-Object {
$measure = $Devices["$($_.Miner.Type)"] | Measure-Object Power -Sum
if ($measure) {
$draw = [decimal]$measure[0].Sum
if ($draw -gt 0) {
$_.SetPower($draw)
$draw = $Statistics.SetValue($_.Miner.GetPowerFilename(), $_.Miner.GetKey(), $draw, $Config.AverageHashSpeed)
}
Remove-Variable draw
}
Remove-Variable measure
}
}
}
$Running = $ActiveMiners.Values | Where-Object { $_.State -eq [eState]::Running }
# stop benchmark by condition: timeout reached and has result or timeout more then twice and no result
$Benchs = $Running | Where-Object { $_.Action -eq [eAction]::Benchmark }
if ($Benchs) { Get-Speed $Benchs } # read speed from active miners
$Benchs | ForEach-Object {
$speed = $_.GetSpeed($false)
if (($_.CurrentTime.Elapsed.TotalSeconds -ge $_.Miner.BenchmarkSeconds -and $speed -gt 0) -or
($_.CurrentTime.Elapsed.TotalSeconds -ge ($_.Miner.BenchmarkSeconds * 2) -and $speed -eq 0)) {
$_.Stop($AllAlgos.RunAfter)
if ($speed -eq 0) {
$speed = $Statistics.SetValue($_.Miner.GetFilename(), $_.Miner.GetKey(), -1)
}
else {
$speed = $Statistics.SetValue($_.Miner.GetFilename(), $_.Miner.GetKey(), $speed, $Config.AverageHashSpeed)
if (![string]::IsNullOrWhiteSpace($_.Miner.DualAlgorithm)) {
$speed = $_.GetSpeed($true)
$speed = $Statistics.SetValue($_.Miner.GetFilename(), $_.Miner.GetKey($true), $speed, $Config.AverageHashSpeed)
}
}
}
}
Remove-Variable Benchs
# protection switching between pools
if (!$FastLoop) {
$Running = $Running | Where-Object { $_.State -eq [eState]::Running -and (Get-PoolInfoEnabled $_.Miner.PoolKey $_.Miner.Algorithm $_.Miner.DualAlgorithm) } |
ForEach-Object { $_.Miner } | Where-Object {
$r = $_
# no resistance between unique
if ($r.Priority -ge [Priority]::Solo) { $false }
else {
$null -ne ($AllMiners | Where-Object {
$r.PoolKey -ne $_.PoolKey -and
$r.Priority -eq $_.Priority -and
$r.Name -eq $_.Name -and
$r.Algorithm -eq $_.Algorithm -and
$r.DualAlgorithm -eq $_.DualAlgorithm -and
$r.Type -eq $_.Type
})
}
}
if ($Running -and $Running.Length -gt 0) {
$AllMiners += $Running
}
}
Remove-Variable Running
# read speed and price of proposed miners
$AllMiners = $AllMiners | ForEach-Object {
if (!$FastLoop) {
$speed = $Statistics.GetValue($_.GetFilename(), $_.GetKey())
$speedDual = 0
$dual = $_.IsDual()
if ($dual) {
$speedDual = $Statistics.GetValue($_.GetFilename(), $_.GetKey($true))
}
# filter unused
if ($speed -ge 0) {
$price = (Get-PoolAlgorithmProfit $_.PoolKey $_.Algorithm $_.DualAlgorithm)
if (($_.Priority -gt [Priority]::None -and (!$dual -or $dual -and $_.DualPriority -gt [Priority]::None)) -or
($_.Priority -eq [Priority]::None -and $speed -gt 0 -and ((!$dual -and $price -gt 0) -or
($dual -and $_.DualPriority -gt [Priority]::None -and $speedDual -gt 0 -and $price[0] -gt 0 -and $price[1] -gt 0)))) {
[MinerProfitInfo] $mpi = $null
if (![string]::IsNullOrWhiteSpace($_.DualAlgorithm)) {
$mpi = [MinerProfitInfo]::new($_, $Config, $speed, $price[0], $speedDual, $price[1])
}
else {
$mpi = [MinerProfitInfo]::new($_, $Config, $speed, $price)
}
if ($speed -gt 0) {
if ($_.Priority -eq [Priority]::Solo -and ![Config]::SoloParty.Contains($_.Type)) {
[Config]::SoloParty.Add($_.Type)
}
if (!$KnownAlgos[$_.Type].ContainsKey($_.Algorithm)) {
$KnownAlgos[$_.Type][$_.Algorithm] = [SpeedProfitInfo]::new()
}
$pool = Get-Pool $_.Algorithm
[decimal] $bestPrice = 0
if ($pool) {
$bestPrice = $pool.Extra.bestprofit
}
$KnownAlgos[$_.Type][$_.Algorithm].SetValue($speed, $mpi.Profit, $bestPrice, $_.Priority -eq [Priority]::None -or $_.Priority -eq [Priority]::Unique)
Remove-Variable pool, bestPrice
}
if ($Config.DevicesStatus -and (Get-ElectricityPriceCurrency)) {
$mpi.SetPower($Statistics.GetValue($_.GetPowerFilename(), $_.GetKey()), (Get-ElectricityCurrentPrice "BTC"))
}
$mpi
}
Remove-Variable price
}
}
elseif (!$exit) {
$speed = $Statistics.GetValue($_.Miner.GetFilename(), $_.Miner.GetKey())
$speedDual = 0
$dual = $_.Miner.IsDual()
if ($dual) {
$speedDual = $Statistics.GetValue($_.Miner.GetFilename(), $_.Miner.GetKey($true))
}
# filter unused
if ($speed -ge 0) {
if ($dual) { $_.SetSpeed($speed, $speedDual) } else { $_.SetSpeed($speed) }
if ($Config.DevicesStatus -and (Get-ElectricityPriceCurrency)) {
$_.SetPower($Statistics.GetValue($_.Miner.GetPowerFilename(), $_.Miner.GetKey()), (Get-ElectricityCurrentPrice "BTC"))
}
$_
}
}
} |
# reorder miners for proper output
Sort-Object @{ Expression = { $_.Miner.Type } }, @{ Expression = { $_.Profit }; Descending = $true }, @{ Expression = { $_.Speed }; Descending = $true }, @{ Expression = { $_.Miner.GetExKey() } }
if (!$exit) {
Remove-Variable speed, speedDual, dual
$global:HasBenchmark = $null -ne ($AllMiners | Where-Object { $_.Speed -eq 0 -and (($global:MRRRentedTypes -notcontains ($_.Miner.Type) -and
[Config]::SoloParty -notcontains ($_.Miner.Type) -and $Summary.Loop -gt 1) -or $_.Miner.Priority -ge [Priority]::Solo) } | Select-Object -First 1)
if ($global:HasConfirm -and !$global:HasBenchmark) {
# reset confirm after all bench ends
$global:HasConfirm = $false
}
[Config]::DelayUpdate = $global:MRRRentedTypes -or $Summary.ServiceRunnig() -or (($Summary.TotalTime.Elapsed.TotalSeconds / [Config]::Max) -gt $Summary.FeeTime.Elapsed.TotalSeconds)
# look for run or stop miner
[Config]::ActiveTypes | ForEach-Object {
$type = $_
# variables
if (!$Summary.ServiceRunnig()) {
$allMinersByType = $AllMiners | Where-Object { $_.Miner.Type -eq $type -and $_.Miner.Priority -ge [Priority]::Normal } |
Sort-Object @{ Expression = { [int]($_.Miner.Priority) }; Descending = $true }, @{ Expression = { $_.Profit }; Descending = $true },
@{ Expression = { $_.Speed }; Descending = $true }, @{ Expression = { $_.Miner.GetExKey() } }
}
else {
$allMinersByType = $AllMiners | Where-Object { $_.Miner.Type -eq $type -and $_.Miner.Priority -ge [Priority]::Normal -and $_.Miner.Pool -match [Config]::Pools } |
Sort-Object @{ Expression = { $_.Profit }; Descending = $true }, @{ Expression = { $_.Miner.GetExKey() } }
}
$activeMinersByType = $ActiveMiners.Values | Where-Object { $_.Miner.Type -eq $type }
$activeMinerByType = $activeMinersByType | Where-Object { $_.State -eq [eState]::Running }
$activeMiner = if ($activeMinerByType) { $allMinersByType | Where-Object { $_.Miner.GetUniqueKey() -eq $activeMinerByType.Miner.GetUniqueKey() } } else { $null }
# update pool info on site and benchmarkseconds for active miner
if ($activeMiner -and $activeMinerByType -and $activeMiner.Miner.PoolKey -eq $activeMinerByType.Miner.PoolKey) {
$activeMinerByType.Miner.Pool = $activeMiner.Miner.Pool;
$activeMinerByType.Miner.BenchmarkSeconds = $activeMiner.Miner.BenchmarkSeconds;
}
# place current bench
$run = $null
if ($activeMinerByType -and $activeMinerByType.Action -eq [eAction]::Benchmark) {
$run = $activeMinerByType
}
# find benchmark if not benchmarking
if (!$run -and !$Summary.ServiceRunnig()) {
$run = $allMinersByType | Where-Object { $_.Speed -eq 0 -and ($global:MRRRentedTypes -notcontains ($_.Miner.Type) -and
[Config]::SoloParty -notcontains ($_.Miner.Type) -or $_.Miner.Priority -ge [Priority]::Solo)} | Select-Object -First 1
if ($global:HasConfirm -eq $false -and $run) {
# autoconfirm on one algo
if ($Config.ConfirmBenchmark -and !($AllPools -and $AllPools.Length -eq 1)) {
$run = $null
$global:NeedConfirm = $true
}
else {
$global:HasConfirm = $true;
}
}
}
$lf = Get-ProfitLowerFloor $type $($Summary.ServiceRunnig())
# nothing benchmarking - get most profitable - exclude failed
if (!$run) {
$firstminer = $null
$miner = $null
$miners = @()
$allMinersByType | ForEach-Object {
if (!$run -and ($_.Profit -gt $lf -or $_.Miner.Priority -ge [Priority]::Solo -or ($_.Miner.Priority -eq [Priority]::High -and $_.Profit -eq 0))) {
# reset failed on solo or unique
if ($null -eq $firstminer) {
$firstminer = $_
}
$miner = $_
if ($miner.Miner.Algorithm -eq $firstminer.Miner.Algorithm -and $miner.Miner.Priority -eq $firstminer.Miner.Priority) {
$miners += $miner.Miner.GetUniqueKey()
}
elseif ($firstminer.Miner.Priority -ge [Priority]::Solo) {
$activeMinersByType | Where-Object { $miners -contains $_.Miner.GetUniqueKey() } | ForEach-Object {
$_.ResetFailed()
}
$run = $firstminer;
}
# skip failed or nohash miners
if (!$run -and ($activeMinersByType |
Where-Object { ($_.State -eq [eState]::NoHash -or $_.State -eq [eState]::Failed) -and
$miner.Miner.GetUniqueKey() -eq $_.Miner.GetUniqueKey() }) -eq $null) {
$run = $miner
}
}
}
# copy of above: if only one miner
<#if (!$run -and $firstminer -and $firstminer.Miner.Priority -ge [Priority]::Solo) {
$activeMinersByType | Where-Object { $miners -contains $_.Miner.GetUniqueKey() } | ForEach-Object {
$_.ResetFailed()
}
$run = $firstminer;
}#>
# nothing to run - reset all failed or nohash and run first
if (!$run -and $firstminer) {
$activeMinersByType | Where-Object { $_.State -eq [eState]::NoHash -or $_.State -eq [eState]::Failed } | ForEach-Object {
$_.ResetFailed()
}
$run = $firstminer;
}
Remove-Variable firstminer, miner, miners
}
if ($run -and ($global:HasConfirm -or $global:FChange -or !$activeMinerByType -or ($activeMinerByType -and !$activeMiner) -or !$Config.SwitchingResistance.Enabled -or
($Config.SwitchingResistance.Enabled -and ($run.Miner.Priority -ge [Priority]::Solo -or
$activeMinerByType.CurrentTime.Elapsed.TotalMinutes -ge $Config.SwitchingResistance.Timeout -or
($activeMiner.Profit -gt 0 -and ($run.Profit * 100 / $activeMiner.Profit - 100) -gt $Config.SwitchingResistance.Percent))))) {
$miner = $run.Miner
if (!$ActiveMiners.ContainsKey($miner.GetUniqueKey())) {
$ActiveMiners.Add($miner.GetUniqueKey(), [MinerProcess]::new($miner, $Config))
}
# stop not choosen
$activeMinersByType | Where-Object { $_.State -eq [eState]::Running -and ($miner.GetUniqueKey() -ne $_.Miner.GetUniqueKey() -or $global:FChange) } | ForEach-Object {
$_.Stop($AllAlgos.RunAfter)
}
# run choosen
$mi = $ActiveMiners[$miner.GetUniqueKey()]
if ($mi.State -eq $null -or $mi.State -ne [eState]::Running) {
if ($Statistics.GetValue($mi.Miner.GetFilename(), $mi.Miner.GetKey()) -eq 0 -or $Summary.FeeTime.IsRunning) {
$mi.Benchmark($Summary.FeeTime.IsRunning, $AllAlgos.RunBefore)
}
else {
$mi.Start($Summary.ServiceTime.IsRunning, $AllAlgos.RunBefore)
}
$FastLoop = $false
}
Remove-Variable mi, miner
}
elseif ($run -and $activeMinerByType -and $activeMiner -and $Config.SwitchingResistance.Enabled -and
$run.Miner.GetUniqueKey() -ne $activeMinerByType.Miner.GetUniqueKey() -and
!($activeMinerByType.CurrentTime.Elapsed.TotalMinutes -gt $Config.SwitchingResistance.Timeout -or
($run.Profit * 100 / $activeMiner.Profit - 100) -gt $Config.SwitchingResistance.Percent)) {
$run.SwitchingResistance = $true
}
elseif (!$run -and $lf) {
# stop if lower floor
$activeMinersByType | Where-Object { $_.State -eq [eState]::Running -and $_.Profit -lt $lf } | ForEach-Object {
$_.Stop($AllAlgos.RunAfter)
}
}
Remove-Variable lf, run, activeMiner, activeMinerByType, activeMinersByType, allMinersByType, type
}
$global:FChange = $false
if ($global:API.Running) {
$global:API.MinersRunning = $ActiveMiners.Values | Where-Object { $_.State -eq [eState]::Running } | Select-Object (Get-FormatActiveMinersWeb) | ConvertTo-Html -Fragment
$global:API.ActiveMiners = $ActiveMiners.Values | Where-Object { $_.State -eq [eState]::Running } | Select-Object (Get-FormatActiveMinersApi) | ConvertTo-Json -Depth 10
}
if (!$FastLoop -and ![string]::IsNullOrWhiteSpace($Config.ApiKey) -and
(!$Summary.SendApiTime.IsRunning -or $Summary.SendApiTime.Elapsed.TotalSeconds -gt [Config]::ApiSendTimeout)) {
Write-Host "Send state to online monitoring ..." -ForegroundColor Green
$json = Get-JsonForMonitoring
if (![string]::IsNullOrWhiteSpace($json)) {
# $str = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($json))
# $json = Get-Rest "https://api.mindminer.online/?type=setworker&apikey=$($Config.ApiKey)&worker=$($Config.WorkerName)" "data=$str"
$json = Get-Rest "https://api.mindminer.online/?type=setworker&apikey=$($Config.ApiKey)&worker=$($Config.WorkerName)&timeout=$($Config.LoopTimeout)" $json 1
if ($json -and $json.error) {
Write-Host "Error send state to online monitoring: $($json.error)" -ForegroundColor Red
Start-Sleep -Seconds ($Config.CheckTimeout)
}
$Summary.SendApiTime.Restart();
# Remove-Variable str
}
Remove-Variable json
}
$Statistics.Write([Config]::StatsLocation)
if (!$FastLoop) { $Summary.LoopTime.Restart() }
$verbose = $Config.Verbose -as [eVerbose]
Clear-Host
Out-Header ($verbose -ne [eVerbose]::Minimal)
if ($Config.DevicesStatus) {
Out-DeviceInfo ($verbose -eq [eVerbose]::Minimal)
}
if ($verbose -eq [eVerbose]::Full) {
Out-PoolInfo
}
[decimal] $mult = if ($verbose -eq [eVerbose]::Normal) { 0.70 } else { 0.85 }
$bench = [hashtable]::new()
$max = $AllMiners | Group-Object { $_.Miner.Type } | ForEach-Object {
$bench[$_.Name] = ($_.Group | Where-Object { $_.Speed -eq 0 } | Select-Object @{ Name = "BenchmarkSeconds"; Expression = { $_.Miner.BenchmarkSeconds } } |
Measure-Object BenchmarkSeconds -Sum).Sum
$prft = ($_.Group | Select-Object -First 1).Profit
$val = $_.Group | Where-Object { $_.Miner.Priority -gt [Priority]::None } | Select-Object -First 1
if ($val) { $prft = $val.Profit }
@{ $_.Name = $mult * $prft }
}
Remove-Variable mult
$alg = [hashtable]::new()
Out-Table ($AllMiners | Where-Object {
$uniq = $_.Miner.GetUniqueKey()
$type = $_.Miner.Type
if (!$alg[$type]) { $alg[$type] = [Collections.ArrayList]::new() }
$_.Speed -eq 0 -or (($_.Profit -ge 0.00000001 -or ($_.Profit -eq 0 -and $_.Miner.Priority -eq [Priority]::High)) -and
($verbose -eq [eVerbose]::Full -or
($ActiveMiners.Values | Where-Object { $_.State -ne [eState]::Stopped -and $_.Miner.GetUniqueKey() -eq $uniq } | Select-Object -First 1) -or
(($_.Profit -ge $max."$type" -or $_.Miner.Priority -gt [Priority]::Normal) -and
$alg[$type] -notcontains "$($_.Miner.Algorithm)$($_.Miner.DualAlgorithm)")))
$ivar = $alg[$type].Add("$($_.Miner.Algorithm)$($_.Miner.DualAlgorithm)")
Remove-Variable ivar, type, uniq
} |
Format-Table (Get-FormatMiners) -GroupBy @{ Label = "Type"; Expression = {
$rslt = "$($_.Miner.Type)"
if ($bench[$_.Miner.Type] -gt 0) {
$rslt += ", " + $(if ($global:HasConfirm -eq $true) { "Benchmarking" } else { "Need bench" }) + ": " +
"$([SummaryInfo]::Elapsed([timespan]::FromSeconds($bench[$_.Miner.Type])))"
}
$rslt;
}})
Write-Host "^ Priority, + Running, - No Hash, ! Failed, % Switching Resistance, _ Low Profit, * Specified Coin, ** Solo|Party"
Write-Host
Remove-Variable alg, max, bench
# display active miners
if ($verbose -ne [eVerbose]::Minimal) {
Out-Table ($ActiveMiners.Values | Where-Object { $verbose -eq [eVerbose]::Full -or $_.State -ne [eState]::Stopped } |
Sort-Object { [int]($_.State -as [eState]), [SummaryInfo]::Elapsed($_.TotalTime.Elapsed) } |
Format-Table (Get-FormatActiveMiners ($verbose -eq [eVerbose]::Full)) -GroupBy State -Wrap)
}
if ($Config.ShowBalance) {
Out-PoolBalance ($verbose -eq [eVerbose]::Minimal)
}
Out-Footer
if ($DownloadMiners -and ($DownloadMiners.Length -gt 0 -or $DownloadMiners -is [PSCustomObject])) {
Write-Host "Download miner(s): $(($DownloadMiners | Select-Object Name -Unique | ForEach-Object { $_.Name }) -Join `", `") ... " -ForegroundColor Yellow
}
if ($global:HasConfirm) {
Write-Host "Please observe while the benchmarks are running ..." -ForegroundColor Red
}
if ($PSVersionTable.PSVersion -lt [version]::new(5,1)) {
Write-Host "Please update PowerShell to version 5.1 (https://www.microsoft.com/en-us/download/details.aspx?id=54616)" -ForegroundColor Yellow
}
Remove-Variable verbose
}
$switching = $Config.Switching -as [eSwitching]
do {
$FastLoop = $false
$start = [Diagnostics.Stopwatch]::StartNew()
do {
Start-Sleep -Milliseconds ([Config]::SmallTimeout)
while ([Console]::KeyAvailable -eq $true) {
[ConsoleKeyInfo] $key = [Console]::ReadKey($true)
if (($key.Modifiers -match [ConsoleModifiers]::Alt -or $key.Modifiers -match [ConsoleModifiers]::Control) -and $key.Key -eq [ConsoleKey]::S) {
$items = [enum]::GetValues([eSwitching])
$index = [array]::IndexOf($items, $Config.Switching -as [eSwitching]) + 1
$Config.Switching = if ($items.Length -eq $index) { $items[0] } else { $items[$index] }
Remove-Variable index, items
Write-Host "Switching mode changed to $($Config.Switching)." -ForegroundColor Green
Start-Sleep -Milliseconds ([Config]::SmallTimeout * 2)
$FastLoop = $true
}
elseif ($key.Key -eq [ConsoleKey]::V) {
$items = [enum]::GetValues([eVerbose])
$index = [array]::IndexOf($items, $Config.Verbose -as [eVerbose]) + 1
$Config.Verbose = if ($items.Length -eq $index) { $items[0] } else { $items[$index] }
Remove-Variable index, items
Write-Host "Verbose level changed to $($Config.Verbose)." -ForegroundColor Green
Start-Sleep -Milliseconds ([Config]::SmallTimeout * 2)
$FastLoop = $true
}
elseif (($key.Modifiers -match [ConsoleModifiers]::Alt -or $key.Modifiers -match [ConsoleModifiers]::Control) -and
($key.Key -eq [ConsoleKey]::E -or $key.Key -eq [ConsoleKey]::Q -or $key.Key -eq [ConsoleKey]::X)) {
New-Item ([IO.Path]::Combine([Config]::BinLocation, ".stop")) -ItemType Directory -Force | Out-Null
$exit = $true
# for mrr to disable all rigs
[Config]::ActiveTypes = @()
}
elseif (($key.Modifiers -match [ConsoleModifiers]::Alt -or $key.Modifiers -match [ConsoleModifiers]::Control) -and $key.Key -eq [ConsoleKey]::R) {
New-Item ([IO.Path]::Combine([Config]::BinLocation, ".restart")) -ItemType Directory -Force | Out-Null
$exit = $true
}
elseif ($Config.ShowBalance -and $key.Key -eq [ConsoleKey]::R) {
$Config.ShowExchangeRate = !$Config.ShowExchangeRate;
$FastLoop = $true
}
elseif ($key.Key -eq [ConsoleKey]::C -and !$global:HasConfirm) {
Clear-OldMiners ($ActiveMiners.Values | Where-Object { $_.State -eq [eState]::Running } | ForEach-Object { $_.Miner.Name })
}
elseif ($key.Key -eq [ConsoleKey]::F -and !$global:HasConfirm) {
if (Clear-FailedMiners ($ActiveMiners.Values | Where-Object { $_.State -eq [eState]::Failed })) {
$FastLoop = $true
}
}
elseif ($key.Key -eq [ConsoleKey]::T -and !$global:HasConfirm -and [Config]::ActiveTypesInitial.Length -gt 1) {
[Config]::ActiveTypes = Select-ActiveTypes ([Config]::ActiveTypesInitial)
[Config]::ActiveTypesInitial | Where-Object { [Config]::ActiveTypes -notcontains $_ } | ForEach-Object {
$type = $_
$ActiveMiners.Values | Where-Object { $_.Miner.Type -eq $type -and $_.State -eq [eState]::Running } | ForEach-Object {
$_.Stop($AllAlgos.RunAfter)
$KnownAlgos[$type].Clear()
}
Remove-Variable type
}
# for normal loop
$switching = $null
$FastLoop = $true
}
elseif ($key.Key -eq [ConsoleKey]::Y -and $global:HasConfirm -eq $false -and $global:NeedConfirm -eq $true) {
Write-Host "Thanks. " -ForegroundColor Green -NoNewline
Write-Host "Please observe while the benchmarks are running ..." -ForegroundColor Red
Start-Sleep -Milliseconds ([Config]::SmallTimeout * 2)
$global:HasConfirm = $true
$FastLoop = $true
}
elseif ($key.Key -eq [ConsoleKey]::P -and $global:HasConfirm -eq $false -and $global:NeedConfirm -eq $false -and [Config]::UseApiProxy -eq $false) {
$global:AskPools = $true
$FastLoop = $true
}
Remove-Variable key
}
} while ($start.Elapsed.TotalSeconds -lt $Config.CheckTimeout -and !$exit -and !$FastLoop)
Remove-Variable start
# if needed - exit
if ($exit -eq $true) {
Write-Host "Exiting ..." -ForegroundColor Green
if ($global:API.Running) {
Write-Host "Stopping API server ..." -ForegroundColor Green
Stop-ApiServer
}
$ActiveMiners.Values | Where-Object { $_.State -eq [eState]::Running } | ForEach-Object {
$_.Stop($AllAlgos.RunAfter)
}
# stop mrr
if (![string]::IsNullOrWhiteSpace($global:MRRFile) -and [Config]::ActiveTypes.Length -eq 0) {
Invoke-Expression $global:MRRFile | Out-Null
}
exit
}
if (!$FastLoop) {
# read speed while run main loop timeout
$checkMiners = $ActiveMiners.Values | Where-Object { $_.State -eq [eState]::Running }
if ($checkMiners -and $checkMiners.Length -gt 0) {
Get-Speed $checkMiners
# $checkMiners | ForEach-Object { Write-Host "Speed: $([decimal]::Round($_.GetSpeed($false), 2))" }
}
Remove-Variable checkMiners
# check miners work propertly
$ActiveMiners.Values | Where-Object { $_.State -ne [eState]::Stopped } | ForEach-Object {
$prevState = $_.State
if ($_.Check($AllAlgos.RunAfter) -eq [eState]::Failed -and $prevState -ne [eState]::Failed) {
# miner failed - run next