-
Notifications
You must be signed in to change notification settings - Fork 0
/
UG-Miner.ps1
1146 lines (1048 loc) · 89.4 KB
/
UG-Miner.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
<#
Copyright (c) 2018-2024 UselessGuru
UG-Miner is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
UG-Miner is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#>
<#
Product: UG-Miner
File: UG-Miner.ps1
Version: 6.3.13
Version date: 2024/11/10
#>
using module .\Includes\Include.psm1
using module .\Includes\APIServer.psm1
Param(
[Parameter(Mandatory = $false)]
[String[]]$Algorithm = @(), # i.e. @("Equihash1445", "Ethash", "KawPow") etc. If '+' is used, then only the explicitly enabled algorithms are used. If '-' is used, then all algorithms except the disabled ones are used. Do not combine '+' and '-' for the same algorithm.
[Parameter(Mandatory = $false)]
[String]$APILogfile = "", # API will log all requests to this file, leave empty to disable
[Parameter(Mandatory = $false)]
[Int]$APIPort = 3999, # TCP Port for API & Web GUI
[Parameter(Mandatory = $false)]
[Switch]$AutoReboot = $true, # If true will reboot computer when a miner is completely dead, e.g. unresponsive
[Parameter(Mandatory = $false)]
[Switch]$AutoUpdate = $true, # If true will automatically update to the new version
[Parameter(Mandatory = $false)]
[Int]$AutoUpdateCheckInterval = 1, # If true will periodically check for a new program version every n days (0 to disable)
[Parameter(Mandatory = $false)]
[Switch]$BackupOnAutoUpdate = $true, # If true will backup installed version before update to the new version
[Parameter(Mandatory = $false)]
[Double]$BadShareRatioThreshold = 0.05, # Allowed ratio of bad shares (total / bad) as reported by the miner. If the ratio exceeds the configured threshold then the miner will get marked as failed. Allowed values: 0.00 - 1.00. 0 disables this check
[Parameter(Mandatory = $false)]
[Boolean]$BalancesKeepAlive = $true, # If true will force mining at a pool to protect your earnings (some pools auto-purge the wallet after longer periods of inactivity, see '\Data\PoolData.Json' BalancesKeepAlive properties)
[Parameter(Mandatory = $false)]
[Boolean]$BalancesShowSums = $true, # Show 1hr / 6hrs / 24hr / 7day & 30day pool earning sums in web dashboard
[Parameter(Mandatory = $false)]
[Boolean]$BalancesShowAverages = $true, # Show 1hr / 24hr & 7day pool earning averages in web dashboard
[Parameter(Mandatory = $false)]
[Boolean]$BalancesShowInAllCurrencies = $true, # If true pool balances will be shown in all currencies in web dashboard
[Parameter(Mandatory = $false)]
[Boolean]$BalancesShowInFIATcurrency = $true, # If true pool balances will be shown in main currency in web dashboard
[Parameter(Mandatory = $false)]
[String[]]$BalancesTrackerExcludePools = @(), # Balances tracker will not track these pools
[Parameter(Mandatory = $false)]
[Switch]$BalancesTrackerLog = $false, # If true will store all balance tracker data in .\Logs\EarningTrackerLog.csv
[Parameter(Mandatory = $false)]
[UInt16]$BalancesTrackerPollInterval = 5, # minutes, Interval duration to trigger background task to collect pool balances & earnings data; set to 0 to disable
[Parameter(Mandatory = $false)]
[Switch]$BenchmarkAllPoolAlgorithmCombinations,
[Parameter(Mandatory = $false)]
[Switch]$CalculatePowerCost = $true, # If true power consumption will be read from miners and calculate power cost, required for true profit calculation
[Parameter(Mandatory = $false)]
[String]$ConfigFile = ".\Config\Config.json", # Config file name
[Parameter(Mandatory = $false)]
[Int]$CPUMiningReserveCPUcore = 1, # Number of CPU cores reserved for main script processing. Helps to get more stable hashrates and faster core loop processing.
[Parameter(Mandatory = $false)]
[Int]$CPUMinerProcessPriority = "-2", # Process priority for CPU miners
[Parameter(Mandatory = $false)]
[String[]]$Currency = @(), # i.e. @("+ETC", +EVR", "+KIIRO") etc. If '+' is used, then only the explicitly enabled currencies are used. If '-' is used, then all currencies except the disabled ones are used. Do not combine '+' and '-' for the same currency.
[Parameter(Mandatory = $false)]
[Int]$DecimalsMax = 6, # Display numbers with maximal n decimal digits (larger numbers are shown with less decimal digits)
[Parameter(Mandatory = $false)]
[Int]$Delay = 0, # seconds between stop and start of miners, use only when getting blue screens on miner switches
[Parameter(Mandatory = $false)]
[Switch]$DisableCpuMiningOnBattery = $false, # If true will not use CPU miners while running on battery
[Parameter(Mandatory = $false)]
[Switch]$DisableDualAlgoMining = $false, # If true will not use any dual algorithm miners
[Parameter(Mandatory = $false)]
[Switch]$DisableMinerFee = $false, # Set to true to disable miner fees (Note: not all miners support turning off their built in fees, others will reduce the hashrate)
[Parameter(Mandatory = $false)]
[Switch]$DisableMinersWithFee = $false, # Set to true to disable all miners which contain fees
[Parameter(Mandatory = $false)]
[Switch]$DisableSingleAlgoMining = $false, # If true will not use any single algorithm miners
[Parameter(Mandatory = $false)]
[Int]$Donation = 15, # Minutes per Day
[Parameter(Mandatory = $false)]
[Double]$EarningsAdjustmentFactor = 1, # Default adjustment factor for prices reported by ALL pools (unless there is a per pool value configuration definined). Prices will be multiplied with this. Allowed values: 0.0 - 10.0
[Parameter(Mandatory = $false)]
[String[]]$ExcludeDeviceName = @(), # Array of disabled devices, e.g. @("CPU#00", "GPU#02"); by default all devices are enabled
[Parameter(Mandatory = $false)]
[String[]]$ExcludeMinerName = @(), # List of miners to be excluded; Either specify miner short name, e.g. "PhoenixMiner" (without '-v...') to exclude any version of the miner, or use the full miner name incl. version information
[Parameter(Mandatory = $false)]
[String[]]$ExtraCurrencies = @("ETC", "ETH", "mBTC"), # Extra currencies used in balances summary, Enter 'real-world' or crypto currencies, mBTC (milli BTC) is also allowed
[Parameter(Mandatory = $false)]
[String]$FIATcurrency = (Get-Culture).NumberFormat.CurrencySymbol, # Default main 'real-money' currency, i.e. GBP, USD, AUD, NZD etc. Do not use crypto currencies
[Parameter(Mandatory = $false)]
[Int]$GPUMinerProcessPriority = "-1", # Process priority for GPU miners
[Parameter(Mandatory = $false)]
[Switch]$IdleDetection = $false, # If true will start mining only if system is idle for $IdleSec seconds
[Parameter(Mandatory = $false)]
[Int]$IdleSec = 120, # seconds the system must be idle before mining starts (if IdleDetection)
[Parameter(Mandatory = $false)]
[Switch]$IgnoreMinerFee = $false, # If true will ignore miner fee for earning & profit calculation
[Parameter(Mandatory = $false)]
[Switch]$IgnorePoolFee = $false, # If true will ignore pool fee for earning & profit calculation
[Parameter(Mandatory = $false)]
[Switch]$IgnorePowerCost = $false, # If true will ignore power cost in best miner selection, instead miners with best earnings will be selected
[Parameter(Mandatory = $false)]
[Switch]$Ignore0HashrateSample = $false, # If true will ignore 0 hashrate samples when setting miner status to 'warming up'
[Parameter(Mandatory = $false)]
[Int]$Interval = 90, # Average cycle loop duration (seconds), min 60, max 3600
[Parameter(Mandatory = $false)]
[Switch]$LegacyGUI = $false, # If true will start legacy GUI
[Parameter(Mandatory = $false)]
[Switch]$LegacyGUIStartMinimized = $true, # If true will start legacy GUI as minimized window
[Parameter(Mandatory = $false)]
[Switch]$LogBalanceAPIResponse = $false, # If true will log the pool balance API data
[Parameter(Mandatory = $false)]
[String[]]$LogToFile = @("Error", "Warn", "Info", "Verbose"), # Log level detail to be written to log file, see Write-Message function; any of "Debug", "Error", "Info", "MemDbg", "Verbose", "Warn"
[Parameter(Mandatory = $false)]
[String[]]$LogToScreen = @("Error", "Warn", "Info", "Verbose"), # Log level detail to be written to screen, see Write-Message function; any of "Debug", "Error", "Info", "MemDbg", "Verbose", "Warn"
[Parameter(Mandatory = $false)]
[String]$LogViewerConfig = ".\Utils\UG-Miner_LogReader.xml", # Path to external log viewer config file
[Parameter(Mandatory = $false)]
[String]$LogViewerExe = ".\Utils\SnakeTail.exe", # Path to optional external log reader (SnakeTail) [https://github.com/snakefoot/snaketail-net], leave empty to disable
[Parameter(Mandatory = $false)]
[Double]$MinAccuracy = 0.5, # Use only pools with price accuracy greater than the configured value. Allowed values: 0.0 - 1.0 (0% - 100%)
[Parameter(Mandatory = $false)]
[Int]$MinCycle = 1, # Minimum number of cycles a miner must mine the same available algorithm@pool continously before switching is allowed (e.g. 3 would force a miner to stick mining algorithm@pool for min. 3 cycles before switching to another algorithm or pool)
[Parameter(Mandatory = $false)]
[Int]$MinDataSample = 20, # Minimum number of hashrate samples required to store hashrate
[Parameter(Mandatory = $false)]
[Int]$MinerSet = 3, # Defines the set of available miners. 0: Benchmark best miner per algorithm and device only; 1: Benchmark optimal miners (more than one per algorithm and device); 2: Benchmark all miners per algorithm and device (except those in the unprofitable algorithms list); 3: Benchmark most miners per algorithm and device (even those in the unprofitable algorithms list, not recommended)
[Parameter(Mandatory = $false)]
[Double]$MinerSwitchingThreshold = 10, # Will not switch miners unless another miner has n% higher earnings / profit
[Parameter(Mandatory = $false)]
[Switch]$MinerUseBestPoolsOnly = $false, # If true it will use only the best pools for mining. Some miners / algorithms are incompatible with some pools. In this case the miner will not be available. This can impact profitability, but is less CPU heavy. This was the default algorithm for versions older than 5.x
[Parameter(Mandatory = $false)]
[String]$MinerWindowStyle = "minimized", # "minimized": miner window is minimized (default), but accessible; "normal": miner windows are shown normally; "hidden": miners will run as a hidden background task and are not accessible (not recommended)
[Parameter(Mandatory = $false)]
[Switch]$MinerWindowStyleNormalWhenBenchmarking = $true, # If true miner window is shown normal when benchmarking (recommended to better see miner messages)
[Parameter(Mandatory = $false)]
[String]$MiningDutchAPIKey = "", # MiningDutch API Key (required to retrieve balance information)
[Parameter(Mandatory = $false)]
[String]$MiningDutchUserName = "UselessGuru", # MiningDutch username
[Parameter(Mandatory = $false)]
[String]$MiningPoolHubAPIKey = "", # MiningPoolHub API Key (required to retrieve balance information)
[Parameter(Mandatory = $false)]
[String]$MiningPoolHubUserName = "UselessGuru", # MiningPoolHub username
[Parameter(Mandatory = $false)]
[Int]$MinWorker = 25, # Minimum workers mining the algorithm at the pool. If less miners are mining the algorithm then the pool will be disabled. This is also a per pool setting configurable in 'PoolsConfig.json'
# [Parameter(Mandatory = $false)]
# [String]$MonitoringServer = "https://UG-Miner.com", # Monitoring server hostname, default "https://UG-Miner.com"
# [Parameter(Mandatory = $false)]
# [String]$MonitoringUser = "", # Monitoring user ID as registered with monitoring server
[Parameter(Mandatory = $false)]
[String]$NiceHashAPIKey = "", # NiceHash API Key (required to retrieve balance information)
[Parameter(Mandatory = $false)]
[String]$NiceHashAPISecret = "", # NiceHash API Secret (required to retrieve balance information)
[Parameter(Mandatory = $false)]
[String]$NiceHashWallet = "", # NiceHash wallet, if left empty $Wallets[BTC] is used
[Parameter(Mandatory = $false)]
[String]$NiceHashOrganizationId = "", # NiceHash Organization Id (required to retrieve balance information)
[Parameter(Mandatory = $false)]
[Switch]$OpenFirewallPorts = $true, # If true will open firewall ports for all miners (requires admin rights!)
[Parameter(Mandatory = $false)]
[String]$PayoutCurrency = "BTC", # i.e. BTC, LTC, ZEC, ETH etc., Default PayoutCurrency for all pools that have no other currency configured, PayoutCurrency is also a per pool setting (to be configured in 'PoolsConfig.json')
[Parameter(Mandatory = $false)]
[Switch]$PoolAllow0Hashrate = $true, # Allow mining to the pool even when there is 0 (or no) hashrate reported in the API
[Parameter(Mandatory = $false)]
[Int]$PoolAPIallowedFailureCount = 3, # Max number of pool API request attempts
[Parameter(Mandatory = $false)]
[Int]$PoolAPIretryInterval = 3, # Time (in seconds) until pool API request retry. Note: Do not set this value too small to avoid temporary blocking by pool
[Parameter(Mandatory = $false)]
[Int]$PoolAPItimeout = 20, # Time (in seconds) until it aborts the pool request (useful if a pool's API is stuck). Note: do not set this value too small or NM will not be able to get any pool data
[Parameter(Mandatory = $false)]
[String]$PoolsConfigFile = ".\Config\PoolsConfig.json", # PoolsConfig file name
[Parameter(Mandatory = $false)]
[String[]]$PoolName = @("Hiveon", "MiningDutch", "NiceHash", "NLPool", "ProHashing", "ZergPoolCoins", "ZPool"),
[Parameter(Mandatory = $false)]
[Int]$PoolTimeout = 20, # Time (in seconds) until it aborts the pool request (useful if a pool's API is stuck). Note: do not set this value too small or NM will not be able to get any pool data
[Parameter(Mandatory = $false)]
[Hashtable]$PowerPricekWh = @{ "00:00" = 0.26; "12:00" = 0.3 }, # Price of power per kW⋅h (in $Currency, e.g. CHF), valid from HH:mm (24hr format)
[Parameter(Mandatory = $false)]
[Hashtable]$PowerConsumption = @{ }, # Static power consumption per device in watt, e.g. @{ "GPU#03" = 25, "GPU#04 = 55" } (in case HWiNFO cannot read power consumption)
[Parameter(Mandatory = $false)]
[Double]$PowerConsumptionIdleSystemW = 60, # Watt, power consumption of idle system. Part of profit calculation.
[Parameter(Mandatory = $false)]
[Double]$ProfitabilityThreshold = -99, # Minimum profit threshold, if profit is less than the configured value (in $Currency, e.g. CHF) mining will stop (except for benchmarking & power consumption measuring)
[Parameter(Mandatory = $false)]
[String]$ProHashingAPIKey = "", # ProHashing API Key (required to retrieve balance information)
[Parameter(Mandatory = $false)]
[String]$ProHashingMiningMode = "PPS", # Either PPS (Pay Per Share) or PPLNS (Pay per Last N Shares)
[Parameter(Mandatory = $false)]
[String]$ProHashingUserName = "UselessGuru", # ProHashing UserName, if left empty then $UserName is used
[Parameter(Mandatory = $false)]
[String]$Proxy = "", # i.e http://192.0.0.1:8080
[Parameter(Mandatory = $false)]
[String]$Region = "Europe", # Used to determine pool nearest to you. One of "Asia", "Europe", "HongKong", "Japan", "Russia", "USA East", "USA West"
[Parameter(Mandatory = $false)]
[Switch]$ReportToServer = $false, # If true will report worker status to central monitoring server
[Parameter(Mandatory = $false)]
[Switch]$ShowAccuracy = $true, # Show pool data accuracy column in main text window miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowAllMiners = $false, # Always show all miners in main text window miner overview (if false, only the best miners will be shown except when in benchmark / PowerConsumption measurement)
[Parameter(Mandatory = $false)]
[Switch]$ShowChangeLog = $true, # If true will show the changlog when an update is available
[Parameter(Mandatory = $false)]
[Switch]$ShowCoinName = $true, # Show CoinName column in main text window miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowConsole = $true, # If true will console window will be shown
[Parameter(Mandatory = $false)]
[Switch]$ShowCurrency = $true, # Show Currency column in main text window miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowEarning = $true, # Show miner earning column in main text window miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowEarningBias = $true, # Show miner earning bias column in main text window miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowMinerFee = $true, # Show miner fee column in main text window miner overview (if fees are available, t.b.d. in miner files, property '[Double]Fee')
[Parameter(Mandatory = $false)]
[Switch]$ShowPoolBalances = $false, # Display pool balances & earnings information in main text window, requires BalancesTrackerPollInterval -gt 0
[Parameter(Mandatory = $false)]
[Switch]$ShowPool = $true, # Show pool column in main text window miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowPoolFee = $true, # Show pool fee column in main text window miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowPowerCost = $true, # Show power cost column in main text window miner overview (if power price is available, see PowerPricekWh)
[Parameter(Mandatory = $false)]
[Switch]$ShowProfit = $true, # Show miner profit column in main text window miner overview (if power price is available, see PowerPricekWh)
[Parameter(Mandatory = $false)]
[Switch]$ShowProfitBias = $true, # Show miner profit bias column in main text window miner overview (if power price is available, see PowerPricekWh)
[Parameter(Mandatory = $false)]
[Switch]$ShowPowerConsumption = $true, # Show power consumption column in main text window miner overview (if power price is available, see PowerPricekWh)
[Parameter(Mandatory = $false)]
[Switch]$ShowShares = $true, # Show share data in log
[Parameter(Mandatory = $false)]
[Switch]$ShowUser = $false, # Show pool user name column in main text window miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowWorkerStatus = $true, # Show worker status from other rigs (data retrieved from monitoring server)
[Parameter(Mandatory = $false)]
[String]$SSL = "Prefer", # SSL pool connections: One of three values: 'Prefer' (use where available), 'Never' (pools that only allow SSL connections are marked as unavailable) or 'Always' (pools that do not allow SSL are marked as unavailable). This is also a per pool setting configurable in 'PoolsConfig.json'
[Parameter(Mandatory = $false)]
[Switch]$SSLallowSelfSignedCertificate = $false, # If true will allow SSL/TLS connections with self signed certificates (this is a security issue)
[Parameter(Mandatory = $false)]
[String]$StartupMode = "Running", # One of 'Idle', 'Paused' or 'Running'. This is the same as the buttons in the legacy & web GUI
[Parameter(Mandatory = $false)]
[Boolean]$SubtractBadShares = $true, # If true will deduct bad shares when calculating effective hashrates
[Parameter(Mandatory = $false)]
[Int]$SyncWindow = 3, # Cycles. Pool prices must all be all have been collected within the last 'SyncWindow' cycles, otherwise the biased value of older poll price data will get reduced more the older the data is
[Parameter(Mandatory = $false)]
[Switch]$Transcript = $false, # Enable to write PowerShell transcript files (for debugging)
[Parameter(Mandatory = $false)]
[Switch]$UseColorForMinerStatus = $true, # If true miners in web and legacy GUI will be shown with colored background depending on status
[Parameter(Mandatory = $false)]
[Switch]$UsemBTC = $true, # If true will display BTC values in milli BTC
[Parameter(Mandatory = $false)]
[Switch]$UseMinerTweaks = $false, # If true will apply miner specific tweaks, e.g mild overclock. This may improve profitability at the expense of system stability (Admin rights are required)
[Parameter(Mandatory = $false)]
[String]$UIStyle = "light", # light or full. Defines level of info displayed in main text window
[Parameter(Mandatory = $false)]
[Double]$UnrealPoolPriceFactor = 1.5, # Ignore pool if price is more than $Config.UnrealPoolPriceFactor higher than average price of all other pools with same algorithm & currency
[Parameter(Mandatory = $false)]
[Double]$UnrealMinerEarningFactor = 5, # Ignore miner if resulting profit is more than $Config.UnrealPoolPriceFactor higher than average price of all other miners with same algo
[Parameter(Mandatory = $false)]
[Switch]$UseAnycast = $true, # If true pools (currently ZergPool only) will use anycast for best network performance and ping times
[Parameter(Mandatory = $false)]
[Hashtable]$Wallets = @{ "BTC" = "1GPSq8txFnyrYdXL8t6S94mYdF8cGqVQJF" },
[Parameter(Mandatory = $false)]
[Switch]$Watchdog = $true, # if true will automatically put pools and/or miners temporarily on hold it they fail $WatchdogCount times in a row
[Parameter(Mandatory = $false)]
[Int]$WatchdogCount = 3, # Number of watchdog timers
[Parameter(Mandatory = $false)]
[Switch]$WebGUI = $true, # If true launch web GUI (recommended)
[Parameter(Mandatory = $false)]
[String]$WorkerName = [System.Net.Dns]::GetHostName()
)
# Close useless empty cmd window that comes up when starting from cmd file
$ParentProcessId = (Get-CimInstance win32_process -Filter "ProcessId = $PID")[0].ParentProcessId
If ($RootProcess = (Get-CimInstance win32_process -Filter "ProcessId = $ParentProcessId")[0]) { If ($RootProcess[0].Name -eq "conhost.exe") { Stop-Process -Id $RootProcess[0].ParentProcessId -Force } }
Remove-Variable ParentProcessId, RootProcess -ErrorAction Ignore
$ErrorLogFile = "Logs\$((Get-Item $MyInvocation.MyCommand.Path).BaseName)_Error_$(Get-Date -Format "yyyy-MM-dd").txt"
Set-Location (Split-Path $MyInvocation.MyCommand.Path)
$ProcessName = (Get-Item $MyInvocation.MyCommand.Path).BaseName
@"
UG-Miner
Copyright (c) 2018-$([DateTime]::Now.Year) UselessGuru
This is free software, and you are welcome to redistribute it under certain conditions.
https://github.com/UselessGuru/UG-Miner/blob/master/LICENSE
"@
Write-Host "`nCopyright and license notices must be preserved.`n" -ForegroundColor Yellow
# Initialize thread safe global variables
$Global:Config = [Hashtable]::Synchronized(@{ })
$Global:Stats = [Hashtable]::Synchronized(@{ })
$Global:Variables = [Hashtable]::Synchronized(@{ })
# Branding data
$Variables.Branding = [PSCustomObject]@{
BrandName = "UG-Miner"
BrandWebSite = "https://github.com/UselessGuru/UG-Miner"
ProductLabel = "UG-Miner"
Version = [System.Version]"6.3.13"
}
$Global:WscriptShell = New-Object -ComObject Wscript.Shell
$host.UI.RawUI.WindowTitle = "$($Variables.Branding.ProductLabel) $($Variables.Branding.Version)"
If ($PSVersiontable.PSVersion -lt [System.Version]"7.0.0") {
Write-Host "Unsupported PWSH version $($PSVersiontable.PSVersion.ToString()) detected.`n$($Variables.Branding.BrandName) requires at least PWSH version 7.0.0 (Recommended is 7.4.5) which can be downloaded from https://github.com/PowerShell/powershell/releases." -ForegroundColor Red
$Global:WscriptShell.Popup("Unsupported PWSH version $($PSVersiontable.PSVersion.ToString()) detected.`n`n$($Variables.Branding.BrandName) requires at least PWSH version (Recommended is 7.4.5) which can be downloaded from https://github.com/PowerShell/powershell/releases.", 0, "Terminating error - Cannot continue!", 4112) | Out-Null
Exit
}
# Expand paths
$Variables.MainPath = (Split-Path $MyInvocation.MyCommand.Path)
$Variables.ConfigFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($ConfigFile)
$Variables.PoolsConfigFile = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($PoolsConfigFile)
# Create directories
If (-not (Test-Path -LiteralPath ".\Cache" -PathType Container)) { New-Item -Path . -Name "Cache" -ItemType Directory | Out-Null }
If (-not (Test-Path -LiteralPath ".\Config" -PathType Container)) { New-Item -Path . -Name "Config" -ItemType Directory | Out-Null }
If (-not (Test-Path -LiteralPath ".\Logs" -PathType Container)) { New-Item -Path . -Name "Logs" -ItemType Directory | Out-Null }
If (-not (Test-Path -LiteralPath ".\Stats" -PathType Container)) { New-Item "Stats" -ItemType Directory -Force | Out-Null }
$Variables.AllCommandLineParameters = [Ordered]@{ }
($MyInvocation.MyCommand.Parameters.psBase.Keys.Where({ $_ -ne "ConfigFile" -and (Get-Variable $_ -ErrorAction Ignore) }) | Sort-Object).ForEach(
{
$Variables.AllCommandLineParameters.$_ = Get-Variable $_ -ValueOnly
If ($MyInvocation.MyCommandLineParameters.$_ -is [Switch]) { $Variables.AllCommandLineParameters.$_ = [Boolean]$Variables.AllCommandLineParameters.$_ }
Remove-Variable $_
}
)
Write-Host "Preparing environment and loading data files..." -ForegroundColor Yellow
Initialize-Environment
# Read configuration
[Void](Read-Config -ConfigFile $Variables.ConfigFile)
Write-Message -Level Info "Starting $($Variables.Branding.ProductLabel)® v$($Variables.Branding.Version) © 2017-$([DateTime]::Now.Year) UselessGuru..."
Write-Host ""
If (((Get-CimInstance CIM_Process).Where({ $_.CommandLine -like "PWSH* -Command $($Variables.MainPath)*.ps1 *" }).CommandLine).Count -gt 1) {
# Another instance is already running. Try again in 20 seconds (previous instance might be from autoupdate)
Write-Host "Verifying that no other instance of $($Variables.Branding.ProductLabel) is running..."
Start-Sleep -Seconds 20
If (((Get-CimInstance CIM_Process).Where({ $_.CommandLine -like "PWSH* -Command $($Variables.MainPath)*.ps1 *" }).CommandLine).Count -gt 1) {
Write-Host "Terminating Error - Another instance of $($Variables.Branding.ProductLabel) is already running." -ForegroundColor "Red"
$Global:WscriptShell.Popup("Another instance of $($Variables.Branding.ProductLabel) is already running.", 0, "Terminating error - Cannot continue!", 4112) | Out-Null
Exit
}
}
# Internet connection must be available
$NetworkInterface = (Get-NetConnectionProfile).Where({ $_.IPv4Connectivity -eq "Internet" }).InterfaceIndex
$Variables.MyIP = If ($NetworkInterface) { (Get-NetIPAddress -InterfaceIndex $NetworkInterface -AddressFamily IPV4).IPAddress } Else { $null }
If (-not $Variables.MyIP) {
Write-Host "Terminating Error - No internet connection." -ForegroundColor "Red"
$Global:WscriptShell.Popup("No internet connection", 0, "Terminating error - Cannot continue!", 4112) | Out-Null
Exit
}
# Start transcript log
If ($Config.Transcript) { Start-Transcript -Path ".\Debug\$((Get-Item $MyInvocation.MyCommand.Path).BaseName)-Transcript_$(Get-Date -Format "yyyy-MM-dd_HH-mm-ss").log" }
# Start Log reader (SnakeTail) [https://github.com/snakefoot/snaketail-net]
Start-LogReader
# Update config file to include all new config items
If (-not $Config.ConfigFileVersion -or [System.Version]::Parse($Config.ConfigFileVersion) -lt $Variables.Branding.Version) {
Update-ConfigFile -ConfigFile $Variables.ConfigFile
}
If (-not $Variables.FreshConfig) { Write-Message -Level Info "Using configuration file '$($Variables.ConfigFile.Replace("$(Convert-Path ".\")\", ".\"))'." }
ElseIf ((Get-Command "Get-MpPreference") -and (Get-MpComputerStatus)) {
# Exclude from AV scanner
Try {
If (-not $Variables.IsLocalAdmin) { Write-Message -Level Info "Initiating request to exclude the $($Variables.Branding.ProductLabel) directory from Microsoft Defender Antivirus scans to avoid false virus alerts..."; Start-Sleep -Seconds 5 }
Start-Process "pwsh" "-Command Write-Host 'Excluding UG-Miner directory ''$(Convert-Path .)'' from Microsoft Defender Antivirus scans...'; Import-Module Defender -SkipEditionCheck; Add-MpPreference -ExclusionPath '$(Convert-Path .)'" -Verb runAs
Write-Message -Level Info "Excluded the $($Variables.Branding.ProductLabel) directory from Microsoft Defender Antivirus scans."
}
Catch {
$Global:WscriptShell.Popup("Could not exclude the directory`n'$PWD'`n from Microsoft Defender Antivirus scans.`nThis may lead to unpredictable results.", 0, "Terminating error - Cannot continue!", 4112) | Out-Null
Exit
}
# Unblock files
If (Get-Command "Unblock-File" -ErrorAction Ignore) {
If (Get-Item .\* -Stream Zone.*) {
Write-Host "Unblocking files that were downloaded from the internet..." -ForegroundColor Yellow
Get-ChildItem -Path . -Recurse | Unblock-File
}
}
}
Write-Host ""
#Prerequisites check
Write-Message -Level Verbose "Verifying pre-requisites..."
If ([System.Environment]::OSVersion.Version -lt [System.Version]"10.0.0.0") {
Write-Message -Level Error "$($Variables.Branding.ProductLabel) requires at least Windows 10."
$Global:WscriptShell.Popup("$($Variables.Branding.ProductLabel) requires at least Windows 10.", 0, "Terminating error - Cannot continue!", 4112) | Out-Null
Exit
}
$Prerequisites = @(
"$env:SystemRoot\System32\MSVCR120.dll",
"$env:SystemRoot\System32\VCRUNTIME140.dll",
"$env:SystemRoot\System32\VCRUNTIME140_1.dll"
)
If ($PrerequisitesMissing = @($Prerequisites.Where({ -not (Test-Path -LiteralPath $_ -PathType Leaf) }))) {
$PrerequisitesMissing.ForEach({ Write-Message -Level Warn "$_ is missing." })
Write-Message -Level Error "Please install the required runtime modules. Download and extract"
Write-Message -Level Error "https://github.com/UselessGuru/UG-Miner-Extras/releases/download/Visual-C-Runtimes-All-in-One-Sep-2019/Visual-C-Runtimes-All-in-One-Sep-2019.zip"
Write-Message -Level Error "and run 'install_all.bat' (Admin rights are required)."
$Global:WscriptShell.Popup("Prerequisites missing.`nPlease install the required runtime modules.", 0, "Terminating error - Cannot continue!", 4112) | Out-Null
Exit
}
Remove-Variable Prerequisites, PrerequisitesMissing
If ( -not (Get-Command Get-PnpDevice)) {
Write-Message -Level Error "Windows Management Framework 5.1 is missing."
Write-Message -Level Error "Please install the required runtime modules from https://www.microsoft.com/en-us/download/details.aspx?id=54616"
$Global:WscriptShell.Popup("Windows Management Framework 5.1 is missing.`nPlease install the required runtime modules.", 0, "Terminating error - Cannot continue!", 4112) | Out-Null
Exit
}
Write-Message -Level Verbose "Pre-requisites verification OK - Running PWSH version $([String]($PSVersionTable.PSVersion))."
# Check if new version is available
Get-Version
$Variables.VerthashDatPath = ".\Cache\VertHash.dat"
If (Test-Path -LiteralPath $Variables.VerthashDatPath -PathType Leaf) {
Write-Message -Level Verbose "Verifying integrity of VertHash data file '$($Variables.VerthashDatPath)'..."
}
$VertHashDatCheckJob = Start-ThreadJob -ScriptBlock { (Get-FileHash -Path ".\Cache\VertHash.dat").Hash -eq "A55531E843CD56B010114AAF6325B0D529ECF88F8AD47639B6EDEDAFD721AA48" } -StreamingHost $null -ThrottleLimit ((Get-CimInstance CIM_VideoController).Count + 1)
Write-Host "Importing modules..." -ForegroundColor Yellow
Try {
Add-Type -Path ".\Cache\~OpenCL_$($PSVersionTable.PSVersion.ToString()).dll" -ErrorAction Stop
}
Catch {
If (Test-Path -LiteralPath ".\Cache\~OpenCL_$($PSVersionTable.PSVersion.ToString()).dll" -ErrorAction Ignore) { Remove-Item ".\Cache\~OpenCL_$($PSVersionTable.PSVersion.ToString()).dll" -Force }
Add-Type -Path ".\Includes\OpenCL\*.cs" -OutputAssembly ".\Cache\~OpenCL_$($PSVersionTable.PSVersion.ToString()).dll"
Add-Type -Path ".\Cache\~OpenCL_$($PSVersionTable.PSVersion.ToString()).dll"
}
Try {
Add-Type -Path ".\Cache\~CPUID_$($PSVersionTable.PSVersion.ToString()).dll" -ErrorAction Stop
}
Catch {
If (Test-Path -LiteralPath ".\Cache\~CPUID_$($PSVersionTable.PSVersion.ToString()).dll" -ErrorAction Ignore) { Remove-Item ".\Cache\~CPUID_$($PSVersionTable.PSVersion.ToString()).dll" -Force }
Add-Type -Path ".\Includes\CPUID.cs" -OutputAssembly ".\Cache\~CPUID_$($PSVersionTable.PSVersion.ToString()).dll"
Add-Type -Path ".\Cache\~CPUID_$($PSVersionTable.PSVersion.ToString()).dll"
}
Import-Module NetSecurity -ErrorAction Ignore
Import-Module Defender -ErrorAction Ignore -SkipEditionCheck
Write-Message -Level Verbose "Setting variables..."
$nl = "`n" # Must use variable, cannot join with "`n" with Write-Host
# Getting exchange rates
[Void](Get-Rate)
# Align CUDA id with nvidia-smi order
$env:CUDA_DEVICE_ORDER = "PCI_BUS_ID"
# For AMD
$env:GPU_FORCE_64BIT_PTR = 1
$env:GPU_MAX_HEAP_SIZE = 100
$env:GPU_USE_SYNC_OBJECTS = 1
$env:GPU_MAX_ALLOC_PERCENT = 100
$env:GPU_SINGLE_ALLOC_PERCENT = 100
$env:GPU_MAX_WORKGROUP_SIZE = 256
$Variables.BrainData = @{ }
$Variables.Brains = @{ }
$Variables.CoreLoopCounter = [Int64]0
$Variables.CPUfeatures = (Get-CpuId).Features | Sort-Object
$Variables.CycleStarts = @()
$Variables.IsLocalAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")
$Variables.LastDonated = [DateTime]::Now.AddDays(-1).AddHours(1)
$Variables.MiningEarning = $Variables.MiningProfit = $Variables.MiningPowerCost = [Double]::NaN
$Variables.NewMiningStatus = If ($Config.StartupMode -match "Paused|Running") { $Config.StartupMode } Else { "Idle" }
$Variables.RestartCycle = $true
$Variables.ScriptStartTime = (Get-Process -Id $PID).StartTime.ToUniversalTime()
$Variables.SuspendCycle = $false
$Variables.WatchdogTimers = [PSCustomObject[]]@()
$Variables.RegexAlgoIsEthash = "^Autolykos2|^Ethash|^EtcHash|^UbqHash"
$Variables.RegexAlgoIsProgPow = "^EvrProgPow|^FiroPow|^KawPow|^MeowPow|^ProgPow|^SCCpow"
$Variables.RegexAlgoHasDynamicDAG = "^Autolykos2|^Ethash|^EtcHash|^EvrProgPow|^FiroPow|^KawPow|^MeowPow|^Octopus|^ProgPow|^SCCpow|^UbqHash"
$Variables.RegexAlgoHasStaticDAG = "^FishHash|^HeavyHashKarlsenV2$"
$Variables.RegexAlgoHasDAG = (($Variables.RegexAlgoHasDynamicDAG -split '\|') + ($Variables.RegexAlgoHasStaticDAG) | Sort-Object) -join '|'
$Variables.Summary = "Loading miner device information.<br>This may take a while..."
Write-Message -Level Verbose $Variables.Summary
$Variables.SupportedCPUDeviceVendors = @("AMD", "INTEL")
$Variables.SupportedGPUDeviceVendors = @("AMD", "INTEL", "NVIDIA")
$Variables.GPUArchitectureDbNvidia.PSObject.Properties.ForEach({ $_.Value.Model = $_.Value.Model -join "|" })
$Variables.GPUArchitectureDbAMD.PSObject.Properties.ForEach({ $_.Value = $_.Value -join "|" })
$Variables.Devices = Get-Device
$Variables.Devices.Where({ $_.Type -eq "CPU" -and $_.Vendor -notin $Variables.SupportedCPUDeviceVendors }).ForEach({ $_.State = [DeviceState]::Unsupported; $_.Status = "Unavailable"; $_.StatusInfo = "Unsupported CPU vendor: '$($_.Vendor)'" })
$Variables.Devices.Where({ $_.Type -eq "GPU" -and $_.Vendor -notin $Variables.SupportedGPUDeviceVendors }).ForEach({ $_.State = [DeviceState]::Unsupported; $_.Status = "Unavailable"; $_.StatusInfo = "Unsupported GPU vendor: '$($_.Vendor)'" })
$Variables.Devices.Where({ $_.State -ne [DeviceState]::Unsupported -and $_.Type -eq "GPU" -and -not ($_.CUDAversion -or $_.OpenCL.DriverVersion) }).ForEach({ $_.State = [DeviceState]::Unsupported; $_.Status = "Unavailable"; $_.StatusInfo = "Unsupported GPU model: '$($_.Model)'" })
$Variables.Devices.Where({ $Config.ExcludeDeviceName -contains $_.Name -and $_.State -ne [DeviceState]::Unsupported }).ForEach({ $_.State = [DeviceState]::Disabled; $_.Status = "Idle"; $_.StatusInfo = "Disabled (ExcludeDeviceName: '$($_.Name)')" })
# Build driver version table
$Variables.DriverVersion = [PSCustomObject]@{ }
If ($Variables.Devices.CUDAversion) { $Variables.DriverVersion | Add-Member "CUDA" ($Variables.Devices.CUDAversion | Sort-Object -Top 1) }
$Variables.DriverVersion | Add-Member "CIM" ([PSCustomObject]@{ })
$Variables.DriverVersion.CIM | Add-Member "CPU" ([System.Version](($Variables.Devices.Where({ $_.Type -eq "CPU" }).CIM.DriverVersion | Select-Object -First 1) -split " " | Select-Object -First 1))
$Variables.DriverVersion.CIM | Add-Member "AMD" ([System.Version](($Variables.Devices.Where({ $_.Type -eq "GPU" -and $_.Vendor -eq "AMD" }).CIM.DriverVersion | Select-Object -First 1) -split " " | Select-Object -First 1))
$Variables.DriverVersion.CIM | Add-Member "NVIDIA" ([System.Version](($Variables.Devices.Where({ $_.Type -eq "GPU" -and $_.Vendor -eq "NVIDIA" }).CIM.DriverVersion | Select-Object -First 1) -split " " | Select-Object -First 1))
$Variables.DriverVersion | Add-Member "OpenCL" ([PSCustomObject]@{ })
$Variables.DriverVersion.OpenCL | Add-Member "CPU" ([System.Version](($Variables.Devices.Where({ $_.Type -eq "CPU" }).OpenCL.DriverVersion | Select-Object -First 1) -split " " | Select-Object -First 1))
$Variables.DriverVersion.OpenCL | Add-Member "AMD" ([System.Version](($Variables.Devices.Where({ $_.Type -eq "GPU" -and $_.Vendor -eq "AMD" }).OpenCL.DriverVersion | Select-Object -First 1) -split " " | Select-Object -First 1))
$Variables.DriverVersion.OpenCL | Add-Member "NVIDIA" ([System.Version](($Variables.Devices.Where({ $_.Type -eq "GPU" -and $_.Vendor -eq "NVIDIA" }).OpenCL.DriverVersion | Select-Object -First 1) -split " " | Select-Object -First 1))
# Driver version changed
If ((Test-Path -LiteralPath ".\Cache\DriverVersion.json" -PathType Leaf) -and ([System.IO.File]::ReadAllLines("$PWD\Cache\DriverVersion.json") | ConvertFrom-Json | ConvertTo-Json -Compress) -ne ($Variables.DriverVersion | ConvertTo-Json -Compress)) { Write-Message -Level Warn "Graphics card driver version data has changed. It is recommended to re-benchmark all miners." }
$Variables.DriverVersion | ConvertTo-Json | Out-File -LiteralPath ".\Cache\DriverVersion.json" -Force
# Rename existing switching log
If (Test-Path -LiteralPath ".\Logs\SwitchingLog.csv" -PathType Leaf) { Get-ChildItem -Path ".\Logs\SwitchingLog.csv" -File | Rename-Item -NewName { "SwitchingLog$($_.LastWriteTime.toString("_yyyy-MM-dd_HH-mm-ss")).csv" } }
If ($VertHashDatCheckJob | Wait-Job -Timeout 60 | Receive-Job -Wait -AutoRemoveJob) {
Write-Message -Level Verbose "VertHash data file integrity check: OK."
}
Else {
If (Test-Path -LiteralPath $Variables.VerthashDatPath -PathType Leaf -ErrorAction Ignore) {
Remove-Item -Path $Variables.VerthashDatPath -Force
Write-Message -Level Warn "VertHash data file '$($Variables.VerthashDatPath)' is corrupt -> file deleted. It will be re-downloaded if needed."
}
}
Remove-Variable VertHashDatCheckJob
# Start API server
If ($Config.WebGUI) { Start-APIServer }
# Set process priority to BelowNormal to avoid hashrate drops on systems with weak CPUs
(Get-Process -Id $PID).PriorityClass = "BelowNormal"
Function MainLoop {
If ($Config.BalancesTrackerPollInterval -gt 0 -and $Variables.NewMiningStatus -ne "Idle") { Start-BalancesTracker } Else { Stop-BalancesTracker }
If ($Variables.NewMiningStatus -ne "Idle" -and $Variables.RatesUpdated -lt [DateTime]::Now.ToUniversalTime().AddMinutes( - 15)) {
# Update rates every 15 minutes
[Void](Get-Rate)
If ($Variables.NewMiningStatus -eq "paused") { $Variables.RefreshNeeded = $true }
}
# If something (pause button, idle timer, WebGUI/config) has set the RestartCycle flag, stop and start mining to switch modes immediately
If ($Variables.RestartCycle -or ($LegacyGUIform -and -not $LegacyGUIminingSummaryLabel.Text)) {
$Variables.RestartCycle = $false
If ($Variables.NewMiningStatus -ne $Variables.MiningStatus) {
If ($LegacyGUIform) { Update-GUIstatus }
If ($Variables.NewMiningStatus -eq "Running" -and $Config.IdleDetection) { Write-Message -Level Verbose "Idle detection is enabled. Mining will get suspended on any keyboard or mouse activity." }
# Keep only the last 10 files
Get-ChildItem -Path ".\Logs\$($Variables.Branding.ProductLabel)_*.log" -File | Sort-Object -Property LastWriteTime | Select-Object -SkipLast 10 | Remove-Item -Force -Recurse
Get-ChildItem -Path ".\Logs\SwitchingLog_*.csv" -File | Sort-Object -Property LastWriteTime | Select-Object -SkipLast 10 | Remove-Item -Force -Recurse
Get-ChildItem -Path "$($Variables.ConfigFile)_*.backup" -File | Sort-Object -Property LastWriteTime | Select-Object -SkipLast 10 | Remove-Item -Force -Recurse
If ([Net.ServicePointManager]::SecurityProtocol -notmatch [Net.SecurityProtocolType]::Tls12) { [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 }
If ($Config.Proxy -eq "") { $PSDefaultParameterValues.Remove("*:Proxy") }
Else { $PSDefaultParameterValues["*:Proxy"] = $Config.Proxy }
Stop-Brain @($Variables.Brains.psBase.Keys.Where({ $_ -notin (Get-PoolBaseName $Variables.PoolName) }))
Switch ($Variables.NewMiningStatus) {
"Idle" {
If ($Variables.MiningStatus) {
$Variables.Summary = "'Stop Mining' button clicked."
Write-Host ""
Write-Message -Level Info $Variables.Summary
Close-CoreRunspace
Stop-Brain
# If ($Config.ReportToServer) { Write-MonitoringData }
}
If (-not $Variables.ConfigurationHasChangedDuringUpdate) {
Write-Host ""
$Variables.Summary = "$($Variables.Branding.ProductLabel) is stopped.<br>Click the 'Start mining' button to make money."
Write-Message -Level Info ($Variables.Summary -replace "<br>", " ")
}
Break
}
"Paused" {
$Variables.Summary = "'Pause Mining' button clicked."
Write-Host ""
Write-Message -Level Info $Variables.Summary
If ($Global:CoreRunspace.Job.IsCompleted -eq $false) {
$Global:CoreRunspace.PowerShell.Stop()
$Variables.Remove("EndCycleTime")
$Variables.Remove("Timer")
}
#Stop all miners
ForEach ($Miner in $Variables.Miners.Where({ [MinerStatus]::Running, [MinerStatus]::DryRun -contains $_.Status })) {
$Miner.SetStatus([MinerStatus]::Idle)
$Variables.Devices.Where({ $Miner.DeviceNames -contains $_.Name }).ForEach({ $_.Status = $Miner.Status; $_.StatusInfo = $Miner.StatusInfo; $_.SubStatus = $Miner.SubStatus })
}
Remove-Variable Miner -ErrorAction Ignore
$Variables.MinersBest = [Miner[]]@()
$Variables.MinersRunning = [Miner[]]@()
$Variables.MiningEarning = $Variables.MiningProfit = $Variables.MiningPowerCost = $Variables.MiningPowerConsumption = [Double]0
Start-Brain @(Get-PoolBaseName $Variables.PoolName)
# If ($Config.ReportToServer) { Write-MonitoringData }
Write-Host ""
$Variables.Summary = "$($Variables.Branding.ProductLabel) is paused.<br>"
Write-Message -Level Info ($Variables.Summary -replace "<br>", " ")
((@(If ($Config.UsemBTC) { "mBTC" } Else { ($Config.PayoutCurrency) }) + @($Config.ExtraCurrencies)) | Select-Object -Unique).Where({ $Variables.Rates.$_.($Config.FIATcurrency) }).ForEach(
{
$Variables.Summary += "1 $_ = {0:N$(Get-DecimalsFromValue -Value $Variables.Rates.$_.($Config.FIATcurrency) -DecimalsMax $Config.DecimalsMax)} $($Config.FIATcurrency)   " -f $Variables.Rates.$_.($Config.FIATcurrency)
}
)
$Variables.Summary += "<br>Click the 'Start mining' button to make money."
Break
}
"Running" {
If ($Variables.MiningStatus) {
$Variables.Summary = "'Start Mining' button clicked. Mining processes are starting..."
Write-Host ""
Write-Message -Level Info $Variables.Summary
}
Start-Brain @(Get-PoolBaseName $Config.PoolName)
Start-Core
Break
}
}
$Variables.MiningStatus = $Variables.NewMiningStatus
}
}
If ($Config.ShowConsole) {
Show-Console
If ($host.UI.RawUI.KeyAvailable) {
$KeyPressed = [System.Console]::ReadKey($true)
If ($Variables.NewMiningStatus -eq "Running" -and $KeyPressed.Key -eq "p" -and $KeyPressed.Modifiers -eq 5 <# <Alt><Ctrl>#>) {
If (-not $Global:CoreRunspace.AsyncObject.IsCompleted -eq $false) {
# Core is complete / gone. Cycle cannot be suspended anymore
$Variables.SuspendCycle = $false
}
Else {
$Variables.SuspendCycle = -not $Variables.SuspendCycle
If ($Variables.SuspendCycle) {
$Message = "'<Ctrl><Alt>P' pressed. Core cycle is suspended until you press '<Ctrl><Alt>P' again."
If ($LegacyGUIform) {
$LegacyGUIminingSummaryLabel.ForeColor = [System.Drawing.Color]::Blue
$LegacyGUIminingSummaryLabel.Text = $Message
$LegacyGUIbuttonPause.Enabled = $false
}
Write-Host $Message -ForegroundColor Cyan
}
Else {
$Message = "'<Ctrl><Alt>P' pressed. Core cycle is running again."
If ($LegacyGUIform) {
$LegacyGUIminingSummaryLabel.ForeColor = [System.Drawing.Color]::Blue
$LegacyGUIminingSummaryLabel.Text = $Message
$LegacyGUIbuttonPause.Enabled = $true
}
Write-Host $Message -ForegroundColor Cyan
If ([DateTime]::Now.ToUniversalTime() -gt $Variables.EndCycleTime) { $Variables.EndCycleTime = [DateTime]::Now.ToUniversalTime() }
}
Remove-Variable Message
}
}
Else {
Switch ($KeyPressed.KeyChar) {
"1" {
$Variables.ShowPoolBalances = -not $Variables.ShowPoolBalances
Write-Host "`nListing pool balances set to [" -NoNewline; If ($Variables.ShowPoolBalances) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
"2" {
$Variables.ShowAllMiners = -not $Variables.ShowAllMiners
Write-Host "`nListing all optimal miners set to [" -NoNewline; If ($Variables.ShowAllMiners) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
"3" {
$Variables.UIStyle = If ($Variables.UIStyle -eq "light") { "full" } Else { "light" }
Write-Host "`nUI style set to [" -NoNewline; Write-Host "$($Variables.UIStyle)" -ForegroundColor Blue -NoNewline; Write-Host "] (Information about miners run in the past 24hrs, failed miners in the past 24hrs & watchdog timers will " -NoNewline; If ($Variables.UIStyle -eq "light") { Write-Host "not " -ForegroundColor Red -NoNewline }; Write-Host "be shown)"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
"a" {
$Variables.ShowAccuracy = -not $Variables.ShowAccuracy
Write-Host "`n'" -NoNewline; Write-Host "A" -ForegroundColor Cyan -NoNewline; Write-Host "ccuracy' column visibility set to [" -NoNewline; If ($Variables.ShowAccuracy) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
"c" {
If ($Variables.CalculatePowerCost) {
$Variables.ShowPowerCost = -not $Variables.ShowPowerCost
Write-Host "`n'Power " -NoNewline; Write-Host "C" -ForegroundColor Cyan -NoNewline; Write-Host "ost' column visibility set to [" -NoNewline; If ($Variables.ShowPowerCost) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
}
Break
}
"e" {
$Variables.ShowEarning = -not $Variables.ShowEarning
Write-Host "`n'" -NoNewline; Write-Host "E" -ForegroundColor Cyan -NoNewline; Write-Host "arnings' column visibility set to [" -NoNewline; If ($Variables.ShowEarning) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
"f" {
$Variables.ShowPoolFee = -not $Variables.ShowPoolFee
Write-Host "`n'Pool "-NoNewline; Write-Host "F" -ForegroundColor Cyan -NoNewline; Write-Host "ees' column visibility set to [" -NoNewline; If ($Variables.ShowPoolFee) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
"h" {
Write-Host "`nHot key legend:"
Write-Host "1: Toggle listing pool balances [" -NoNewline; If ($Variables.ShowPoolBalances) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Write-Host "2: Toggle listing all optimal miners [" -NoNewline; If ($Variables.ShowAllMiners) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Write-Host "3: Toggle UI style [full or light] [" -NoNewline; Write-Host "$($Variables.UIStyle)" -ForegroundColor Blue -NoNewline; Write-Host "]"
Write-Host
Write-Host "a: Toggle '" -NoNewline; Write-Host "A" -ForegroundColor Cyan -NoNewline; Write-Host "ccuracy' column visibility [" -NoNewline; If ($Variables.ShowAccuracy) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
If ($Variables.CalculatePowerCost) {
Write-Host "c: Toggle 'Power " -NoNewline; Write-Host "c" -ForegroundColor Cyan -NoNewline; Write-Host "ost' column visibility [" -NoNewline; If ($Variables.ShowPowerCost) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
}
Write-Host "e: Toggle '" -NoNewline; Write-Host "E" -ForegroundColor Cyan -NoNewline; Write-Host "arnings' column visibility [" -NoNewline; If ($Variables.ShowEarning) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Write-Host "f: Toggle pool '" -NoNewline; Write-Host "F" -ForegroundColor Cyan -NoNewline; Write-Host "ees' column visibility [" -NoNewline; If ($Variables.ShowPoolFee) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Write-Host "i: Toggle 'Earning b" -NoNewline; Write-Host "i" -ForegroundColor Cyan -NoNewline; Write-Host "as' column visibility [" -NoNewline; If ($Variables.ShowEarningBias) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Write-Host "m: Toggle " -NoNewline; Write-Host "M" -ForegroundColor Cyan -NoNewline; Write-Host "iner 'fees' column visibility [" -NoNewline; If ($Variables.ShowMinerFee) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Write-Host "n: Toggle 'Coin" -NoNewline; Write-Host "N" -ForegroundColor Cyan -NoNewline; Write-Host "ame' column visibility [" -NoNewline; If ($Variables.ShowCoinName) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Write-Host "p: Toggle '" -NoNewline; Write-Host "P" -ForegroundColor Cyan -NoNewline; Write-Host "ool' column visibility [" -NoNewline; If ($Variables.ShowPool) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
If ($Variables.CalculatePowerCost) {
Write-Host "r: Toggle 'P" -NoNewline; Write-Host "r" -ForegroundColor Cyan -NoNewline; Write-Host "ofit bias' column visibility [" -NoNewline; If ($Variables.ShowProfitBias) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
}
If ($Variables.CalculatePowerCost) {
Write-Host "t: Toggle 'Profi" -NoNewline; Write-Host "t" -ForegroundColor Cyan -NoNewline; Write-Host "' column visibility [" -NoNewline; If ($Variables.ShowProfit) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
}
Write-Host "u: Toggle '" -NoNewline; Write-Host "U" -ForegroundColor Cyan -NoNewline; Write-Host "ser' column visibility [" -NoNewline; If ($Variables.ShowUser) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
If ($Variables.CalculatePowerCost) {
Write-Host "w: Toggle 'Po" -NoNewline; Write-Host "w" -ForegroundColor Cyan -NoNewline; Write-Host "er consumption' column visibility [" -NoNewline; If ($Config.CalculatePowerCost -and $Variables.ShowPowerConsumption) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
}
Write-Host "y: Toggle 'Currenc" -NoNewline; Write-Host "y" -ForegroundColor Cyan -NoNewline; Write-Host "' column visibility [" -NoNewline; If ($Variables.ShowCurrency) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Break
}
"i" {
$Variables.ShowEarningBias = -not $Variables.ShowEarningBias
Write-Host "`n'Earning b" -NoNewline; Write-Host "i" -ForegroundColor Cyan -NoNewline; Write-Host "as' column visibility set to [" -NoNewline; If ($Variables.ShowEarningBias) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
"m" {
$Variables.ShowMinerFee = -not $Variables.ShowMinerFee
Write-Host "`nM" -ForegroundColor Cyan -NoNewline; Write-Host "iner 'Fees' column visibility set to [" -NoNewline; If ($Variables.ShowMinerFee) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
"n" {
$Variables.ShowCoinName = -not $Variables.ShowCoinName
Write-Host "`n'Coin" -NoNewline; Write-Host "N" -ForegroundColor Cyan -NoNewline; Write-Host "ame' column visibility set to [" -NoNewline; If ($Variables.ShowCoinName) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
"p" {
$Variables.ShowPool = -not $Variables.ShowPool
Write-Host "`n'" -NoNewline; Write-Host "P" -ForegroundColor Cyan -NoNewline; Write-Host "ool' column visibility set to [" -NoNewline; If ($Variables.ShowPool) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
"r" {
If ($Variables.CalculatePowerCost) {
$Variables.ShowProfitBias = -not $Variables.ShowProfitBias
Write-Host "`n'P" -NoNewline; Write-Host "r" -ForegroundColor Cyan -NoNewline; Write-Host "ofit bias' column visibility set to [" -NoNewline; If ($Variables.ShowProfitBias) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
}
Break
}
"t" {
If ($Variables.CalculatePowerCost) {
$Variables.ShowProfit = -not $Variables.ShowProfit
Write-Host "`n'" -NoNewline; Write-Host "P" -ForegroundColor Cyan -NoNewline; Write-Host "rofit' column visibility set to [" -NoNewline; If ($Variables.ShowProfit) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
}
Break
}
"u" {
$Variables.ShowUser = -not $Variables.ShowUser
Write-Host "`n'" -NoNewline; Write-Host "U" -ForegroundColor Cyan -NoNewline; Write-Host "ser' column visibility set to [" -NoNewline; If ($Variables.ShowUser) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
"w" {
If ($Variables.CalculatePowerCost) {
$Variables.ShowPowerConsumption = -not $Variables.ShowPowerConsumption
Write-Host "`n'Po" -NoNewline; Write-Host "w" -ForegroundColor Cyan -NoNewline; Write-Host "er consumption' column visibility set to [" -NoNewline; If ($Variables.ShowPowerConsumption) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
}
Break
}
"y" {
$Variables.ShowCurrency = -not $Variables.ShowCurrency
Write-Host "`n'Currenc" -NoNewline; Write-Host "y" -ForegroundColor Cyan -NoNewline; Write-Host "' column visibility set to [" -NoNewline; If ($Variables.ShowCurrency) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "]"
Start-Sleep -Seconds 2
$Variables.RefreshNeeded = $true
Break
}
}
}
Remove-Variable KeyPressed
Start-Sleep -Seconds 2
$host.UI.RawUI.FlushInputBuffer()
}
}
Else { Hide-Console }
If ($Variables.MiningStatus -eq "Running") {
If ($Config.IdleDetection) {
If ([Math]::Round([PInvoke.Win32.UserInput]::IdleTime.TotalSeconds) -gt $Config.IdleSec) {
# System was idle long enough, start mining
If ($Global:CoreRunspace.Job.IsCompleted -eq $true) {
$Variables.Summary = "System was idle for $($Config.IdleSec) second$(If ($Config.IdleSec -ne 1) { "s" }).<br>Resuming mining..."
Write-Message -Level Verbose ($Variables.Summary -replace "<br>", " ")
Start-Core
If ($LegacyGUIform) { Update-GUIstatus }
}
}
ElseIf ($Global:CoreRunspace.Job.IsCompleted -eq $false -and $Global:CoreRunspace.StartTime -lt [DateTime]::Now.ToUniversalTime().AddSeconds( 1 )) {
$Message = "System activity detected.<br>Mining is suspended until system is idle for $($Config.IdleSec) second$(If ($Config.IdleSec -ne 1) { "s" })."
Write-Message -Level Verbose ($Message -replace "<br>", " ")
Stop-Core
If ($LegacyGUIform) {
Update-GUIstatus
$LegacyGUIminingSummaryLabel.Text = ""
($Message -split '<br>').ForEach({ $LegacyGUIminingSummaryLabel.Text += "$_`r`n" })
$LegacyGUIminingSummaryLabel.ForeColor = [System.Drawing.Color]::Black
}
$Variables.Summary = $Message
Remove-Variable Message
}
}
ElseIf ($Global:CoreRunspace.Job.IsCompleted -ne $false) {
If ($Variables.Timer) {
Write-Message -Level Warn "Core cycle stopped abnormally - restarting..."
Close-CoreRunspace
}
Start-Core
If ($LegacyGUIform) { Update-GUIstatus }
}
ElseIf (-not $Variables.SuspendCycle -and -not $Variables.MinersBenchmarkingOrMeasuring -and $Variables.BeginCycleTimeCycleTime -and [DateTime]::Now.ToUniversalTime() -gt $Variables.BeginCycleTimeCycleTime.AddSeconds(1.5 *$Config.Interval)) {
# Core watchdog. Sometimes core loop gets stuck
Write-Message -Level Warn "Core cycle is stuck - restarting..."
Stop-Core
Start-Core
}
}
ElseIf ((Test-Path -Path $Variables.PoolsConfigFile) -and (Test-Path -Path $Variables.ConfigFile)) {
If (-not ($Variables.FreshConfig -or $Variables.ConfigurationHasChangedDuringUpdate) -and $Variables.ConfigFileTimestamp -ne (Get-Item -Path $Variables.ConfigFile).LastWriteTime -or $Variables.PoolsConfigFileTimestamp -ne (Get-Item -Path $Variables.PoolsConfigFile).LastWriteTime) {
[Void](Read-Config -ConfigFile $Variables.ConfigFile)
Write-Message -Level Verbose "Activated changed configuration."
}
}
If ($Variables.RefreshNeeded) {
$Variables.RefreshNeeded = $false
$host.UI.RawUI.WindowTitle = "$($Variables.Branding.ProductLabel) $($Variables.Branding.Version) - Runtime: {0:dd} days {0:hh} hrs {0:mm} mins - Path: $($Variables.Mainpath)" -f [TimeSpan]([DateTime]::Now.ToUniversalTime() - $Variables.ScriptStartTime)
If ($LegacyGUIform) { Update-GUIstatus }
If ($Config.WebGUI) { Start-APIServer } Else { Stop-APIServer }
If ($Config.ShowConsole) {
If ($Variables.MinersRunning) { Clear-Host }
# Get and display earnings stats
If ($Variables.Balances -and $Variables.ShowPoolBalances) {
$Variables.Balances.Values.ForEach(
{
If ($_.PayoutThresholdCurrency -eq "BTC" -and $Config.UsemBTC) { $PayoutCurrency = "mBTC"; $mBTCfactor = 1000 } Else { $PayoutCurrency = $_.PayoutCurrencyCurrency; $mBTCfactor = 1 }
If ($_.Currency -ne $_.PayoutThresholdCurrency) {
# Payout threshold currency is different from asset currency
If ($_.PayoutThresholdCurrency -and $Variables.Rates.($_.Currency) -and $Variables.Rates.($_.PayoutThresholdCurrency)) {
$Percentage = ($_.Balance / $_.PayoutThreshold * $Variables.Rates.($_.Currency).($_.PayoutThresholdCurrency)).toString("P2")
}
Else { $Percentage = "Unknown %"}
}
Else { $Percentage = ($_.Balance / $_.PayoutThreshold).ToString("P2") }
Write-Host "$($_.Pool) [$($_.Wallet)]" -ForegroundColor Green
If ($Variables.Rates.($_.Currency).($Config.FIATcurrency)) {
If ($Config.BalancesShowSums) {
Write-Host ("Earnings last 1 hour: {0:n$($Config.DecimalsMax)} {1} / {2:n$($Config.DecimalsMax)} {3}" -f ($_.Growth1 * $mBTCfactor), $_.Currency, ($_.Growth1 * $Variables.Rates.($_.Currency).($Config.FIATcurrency)), $Config.FIATcurrency)
Write-Host ("Earnings last 6 hours: {0:n$($Config.DecimalsMax)} {1} / {2:n$($Config.DecimalsMax)} {3}" -f ($_.Growth6 * $mBTCfactor), $_.Currency, ($_.Growth6 * $Variables.Rates.($_.Currency).($Config.FIATcurrency)), $Config.FIATcurrency)
Write-Host ("Earnings last 24 hours: {0:n$($Config.DecimalsMax)} {1} / {2:n$($Config.DecimalsMax)} {3}" -f ($_.Growth24 * $mBTCfactor), $_.Currency, ($_.Growth24 * $Variables.Rates.($_.Currency).($Config.FIATcurrency)), $Config.FIATcurrency)
Write-Host ("Earnings last 7 days: {0:n$($Config.DecimalsMax)} {1} / {2:n$($Config.DecimalsMax)} {3}" -f ($_.Growth168 * $mBTCfactor), $_.Currency, ($_.Growth168 * $Variables.Rates.($_.Currency).($Config.FIATcurrency)), $Config.FIATcurrency)
Write-Host ("Earnings last 30 days: {0:n$($Config.DecimalsMax)} {1} / {2:n$($Config.DecimalsMax)} {3}" -f ($_.Growth720 * $mBTCfactor), $_.Currency, ($_.Growth720 * $Variables.Rates.($_.Currency).($Config.FIATcurrency)), $Config.FIATcurrency)
}
If ($Config.BalancesShowAverages) {
Write-Host ("≈ average / hour: {0:n$($Config.DecimalsMax)} {1} / {2:n$($Config.DecimalsMax)} {3}" -f ($_.AvgHourlyGrowth * $mBTCfactor), $_.Currency, ($_.AvgHourlyGrowth * $Variables.Rates.($_.Currency).($Config.FIATcurrency)), $Config.FIATcurrency)
Write-Host ("≈ average / day: {0:n$($Config.DecimalsMax)} {1} / {2:n$($Config.DecimalsMax)} {3}" -f ($_.AvgDailyGrowth * $mBTCfactor), $_.Currency, ($_.AvgDailyGrowth * $Variables.Rates.($_.Currency).($Config.FIATcurrency)), $Config.FIATcurrency)
Write-Host ("≈ average / week: {0:n$($Config.DecimalsMax)} {1} / {2:n$($Config.DecimalsMax)} {3}" -f ($_.AvgWeeklyGrowth * $mBTCfactor), $_.Currency, ($_.AvgWeeklyGrowth * $Variables.Rates.($_.Currency).($Config.FIATcurrency)), $Config.FIATcurrency)
}
Write-Host "Balance: " -NoNewline; Write-Host ("{0:n$($Config.DecimalsMax)} {1} / {2:n$($Config.DecimalsMax)} {3}" -f ($_.Balance * $mBTCfactor), $_.Currency, ($_.Balance * $Variables.Rates.($_.Currency).($Config.FIATcurrency)), $Config.FIATcurrency) -ForegroundColor Yellow }
Else {
If ($Config.BalancesShowSums) {
Write-Host ("Earnings last 1 hour: {0:n$($Config.DecimalsMax)} {1}" -f ($_.Growth1 * $mBTCfactor), $_.Currency)
Write-Host ("Earnings last 6 hours: {0:n$($Config.DecimalsMax)} {1}" -f ($_.Growth6 * $mBTCfactor), $_.Currency)
Write-Host ("Earnings last 24 hours: {0:n$($Config.DecimalsMax)} {1}" -f ($_.Growth24 * $mBTCfactor), $_.Currency)
Write-Host ("Earnings last 7 days: {0:n$($Config.DecimalsMax)} {1}" -f ($_.Growth168 * $mBTCfactor), $_.Currency)
Write-Host ("Earnings last 30 days: {0:n$($Config.DecimalsMax)} {1}" -f ($_.Growth720 * $mBTCfactor), $_.Currency)
}
If ($Config.BalancesShowAverages) {
Write-Host ("≈ average / hour: {0:n$($Config.DecimalsMax)} {1}" -f ($_.AvgHourlyGrowth * $mBTCfactor), $_.Currency)
Write-Host ("≈ average / day: {0:n$($Config.DecimalsMax)} {1}" -f ($_.AvgDailyGrowth * $mBTCfactor), $_.Currency)
Write-Host ("≈ average / week: {0:n$($Config.DecimalsMax)} {1}" -f ($_.AvgWeeklyGrowth * $mBTCfactor), $_.Currency)
}
Write-Host "Balance: " -NoNewline; Write-Host ("{0:n$($Config.DecimalsMax)} {1}" -f ($_.Balance * $mBTCfactor), $_.Currency) -ForegroundColor Yellow
}
Write-Host (" {0} of {1:n$($Config.DecimalsMax)} {2} payment threshold; projected payment date: $(If ($_.ProjectedPayDate -is [DateTime]) { $_.ProjectedPayDate.ToString("G") } Else { $_.ProjectedPayDate })`n" -f $Percentage, ($_.PayoutThreshold * $mBTCfactor), $PayoutCurrency)
}
)
Remove-Variable Currency, mBTCfactor, Percentage -ErrorAction Ignore
}
If ($Variables.MyIP) {
If ($Variables.MiningStatus -eq "Running" -and $Variables.Miners.Where({ $_.Available })) {
# Miner list format
[System.Collections.ArrayList]$MinerTable = @(
@{ Label = "Miner"; Expression = { $_.Name } }
If ($Variables.ShowMinerFee -and ($Variables.Miners.Workers.Fee)) { @{ Label = "Fee"; Expression = { $_.Workers.ForEach({ "{0:P2}" -f [Double]$_.Fee }) }; Align = "right" } }
If ($Variables.ShowEarningBias) { @{ Label = "Earning bias"; Expression = { If ([Double]::IsNaN($_.Earning_Bias)) { "n/a" } Else { "{0:n$($Config.DecimalsMax)}" -f ($_.Earning_Bias * $Variables.Rates.($Config.PayoutCurrency).($Config.FIATcurrency)) } }; Align = "right" } }
If ($Variables.ShowEarning) { @{ Label = "Earning"; Expression = { If ([Double]::IsNaN($_.Earning)) { "n/a" } Else { "{0:n$($Config.DecimalsMax)}" -f ($_.Earning * $Variables.Rates.($Config.PayoutCurrency).($Config.FIATcurrency)) } }; Align = "right" } }
If ($Variables.ShowPowerCost -and $Config.CalculatePowerCost -and $Variables.MiningPowerCost) { @{ Label = "Power cost"; Expression = { If ([Double]::IsNaN($_.PowerConsumption)) { "n/a" } Else { "-{0:n$($Config.DecimalsMax)}" -f ($_.PowerCost * $Variables.Rates.($Config.PayoutCurrency).($Config.FIATcurrency)) } }; Align = "right" } }
If ($Variables.MiningPowerCost -and $Variables.ShowProfitBias) { @{ Label = "Profit bias"; Expression = { If ([Double]::IsNaN($_.Profit_Bias)) { "n/a" } Else { "{0:n$($Config.DecimalsMax)}" -f ($_.Profit_Bias * $Variables.Rates.($Config.PayoutCurrency).($Config.FIATcurrency)) } }; Align = "right" } }
If ($Variables.MiningPowerCost -and $Variables.ShowProfit) { @{ Label = "Profit"; Expression = { If ([Double]::IsNaN($_.Profit)) { "n/a" } Else { "{0:n$($Config.DecimalsMax)}" -f ($_.Profit * $Variables.Rates.($Config.PayoutCurrency).($Config.FIATcurrency)) } }; Align = "right" } }
If ($Variables.ShowPowerConsumption -and $Config.CalculatePowerCost) { @{ Label = "Power (W)"; Expression = { If ($_.MeasurePowerConsumption) { If ($_.Status -eq "Running") { "Measuring..." } Else { "Unmeasured" } } Else { If ([Double]::IsNaN($_.PowerConsumption)) { "n/a" } Else { "$($_.PowerConsumption.ToString("N2"))" } } }; Align = "right" } }
If ($Variables.ShowAccuracy) { @{ Label = "Accuracy"; Expression = { $_.Workers.ForEach({ "{0:P0}" -f [Double]$_.Pool.Accuracy }) }; Align = "right" } }
@{ Label = "Algorithm"; Expression = { $_.Workers.Pool.Algorithm } }
If ($Variables.ShowPool) { @{ Label = "Pool"; Expression = { $_.Workers.Pool.Name } } }
If ($Variables.ShowPoolFee -and ($Variables.Miners.Workers.Pool.Fee)) { @{ Label = "Fee"; Expression = { $_.Workers.ForEach({ "{0:P2}" -f [Double]$_.Pool.Fee }) }; Align = "right" } }
@{ Label = "Hashrate"; Expression = { If ($_.Benchmark) { If ($_.Status -eq "Running") { "Benchmarking..." } Else { "Benchmark pending" } } Else { $_.Workers.ForEach({ $_.Hashrate | ConvertTo-Hash }) } }; Align = "right" }
If ($Variables.ShowUser) { @{ Label = "User"; Expression = { $_.Workers.Pool.User } } }
If ($Variables.ShowCurrency) { @{ Label = "Currency"; Expression = { $_.Workers.Pool.Currency } } }
If ($Variables.ShowCoinName) { @{ Label = "CoinName"; Expression = { $_.Workers.Pool.CoinName } } }
)
# Display top 5 optimal miners and all benchmarking of power consumtion measuring miners
$Bias = If ($Variables.CalculatePowerCost -and -not $Config.IgnorePowerCost) { "Profit_Bias" } Else { "Earning_Bias" }
($Variables.Miners.Where({ $_.Optimal -or $_.Benchmark -or $_.MeasurePowerConsumption }) | Group-Object { [String]$_.DeviceNames }).ForEach(
{
$MinersDeviceGroup = $_.Group | Sort-Object { $_.Name, [String]$_.Algorithms } -Unique
$MinersDeviceGroupNeedingBenchmark = @($MinersDeviceGroup.Where({ $_.Benchmark }))
$MinersDeviceGroupNeedingPowerConsumptionMeasurement = @($MinersDeviceGroup.Where({ $_.MeasurePowerConsumption }))
$MinersDeviceGroup.Where(
{
$Variables.ShowAllMiners -or <# List all miners #>
$MinersDeviceGroupNeedingBenchmark -contains $_ -or
$MinersDeviceGroupNeedingPowerConsumptionMeasurement -contains $_ -or
$_.$Bias -ge ($MinersDeviceGroup.$Bias | Sort-Object -Bottom 5 | Select-Object -Index 0) <# Always list at least the top 5 miners per device group #>
}
) | Sort-Object -Property @{ Expression = { $_.Benchmark }; Descending = $true }, @{ Expression = { $_.MeasurePowerConsumption }; Descending = $true }, @{ Expression = { $_.KeepRunning }; Descending = $true }, @{ Expression = { $_.Prioritize }; Descending = $true }, @{ Expression = { $_.$Bias }; Descending = $true }, @{ Expression = { $_.Name }; Descending = $false }, @{ Expression = { $_.Algorithms[0] }; Descending = $false }, @{ Expression = { $_.Algorithms[1] }; Descending = $false } |
Format-Table $MinerTable -GroupBy @{ Name = "Device$(If ($MinersDeviceGroup[0].DeviceNames.Count -gt 1) { " group" })"; Expression = { "$($MinersDeviceGroup[0].DeviceNames -join ",") [$(($Variables.EnabledDevices.Where({ $MinersDeviceGroup[0].DeviceNames -contains $_.Name })).Model -join ", ")]" } } -AutoSize | Out-Host