-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathNemosMiner.ps1
1489 lines (1328 loc) · 92.3 KB
/
NemosMiner.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
using module .\Includes\Include.psm1
<#
Copyright (c) 2018-2021 Nemo, MrPlus & UselessGuru
NemosMiner 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.
NemosMiner 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: NemosMiner
File: NemosMiner.ps1
Version: 3.9.9.62
Version date: 08 August 2021
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[String[]]$Algorithm = @(), # i.e. @("Ethash", "Equihash", "Cryptonight") etc.
[Parameter(Mandatory = $false)]
[Double]$AllowedBadShareRatio = 0.1, # Allowed ratio of bad shares (total / bad) as reported by the miner. If the ratio exceeds the configured threshold then the miner will marked as failed. Allowed values: 0.00 - 1.00. Default of 0 disables this check
[Parameter(Mandatory = $false)]
[Switch]$AutoStart = $false, # If true NemosMiner will start mining automatically
[Parameter(Mandatory = $false)]
[String]$APILogfile = "", # API will log all requests to this file, to disable leave empty
[Parameter(Mandatory = $false)]
[Int]$APIPort = 3999, # TCP Port for API & Web GUI
[Parameter(Mandatory = $false)]
[Boolean]$AutoUpdate = $false, # Autoupdate
[Parameter(Mandatory = $false)]
[Boolean]$BalancesKeepAlive = $true, # If true Nemosminer will force mining at a pool to protect your eranings (some pools auto-purge the wallet after longer periods of inactivity, see '\Includes\PoolData.Json' BalancesKeepAlive properties)
[Parameter(Mandatory = $false)]
[Switch]$BalancesTrackerLog = $false, # If true NemosMiner 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 dataset to 0 to disable
[Parameter(Mandatory = $false)]
[Switch]$CalculatePowerCost = $true, # If true power usage 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]$CPUMinerProcessPriority = "-2", # Process priority for CPU miners
[Parameter(Mandatory = $false)]
[String]$Currency = (Get-Culture).NumberFormat.CurrencySymbol, # Main 'real-money' currency, i.e. GBP, USD, AUD, NZD ect. Do not use crypto currencies
[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]$DisableDualAlgoMining = $false, # If true NemosMiner will not use any dual algo 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 NemosMiner will not use any single algo miners
[Parameter(Mandatory = $false)]
[Int]$Donate = 13, # Minutes per Day
[Parameter(Mandatory = $false)]
[Double]$EarningsAdjustmentFactor = 1, # Default factor with which NemosMiner multiplies the prices reported by ALL pools. Allowed values: 0.0 - 1.0
[Parameter(Mandatory = $false)]
[Switch]$EstimateCorrection = $false, # If true NemosMiner will multiply the algo price by estimate factor (actual_last24h / estimate_last24h) to counter pool overestimated prices
[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 = @("USD", "ETC", "mBTC"), # Extra currencies used in balances summary, Enter 'real-world' or crypto currencies, mBTC (milli BTC) is also allowed
[Parameter(Mandatory = $false)]
[Int]$GPUMinerProcessPriority = "-1", # Process priority for GPU miners
[Parameter(Mandatory = $false)]
[Double]$IdlePowerUsageW = 60, # Watt, Powerusage of idle system. Part of profit calculation.
[Parameter(Mandatory = $false)]
[Int]$IdleSec = 120, # seconds the system must be idle before mining starts (if MineWhenIdle -eq $true)
[Parameter(Mandatory = $false)]
[Switch]$IgnoreMinerFee = $false, # If true NM will ignore miner fee for earning & profit calculation
[Parameter(Mandatory = $false)]
[Switch]$IgnorePoolFee = $false, # If true NM will ignore pool fee for earning & profit calculation
[Parameter(Mandatory = $false)]
[Switch]$IgnorePowerCost = $false, # If true NM will ignore power cost in best miner selection, instead miners with best earnings will be selected
[Parameter(Mandatory = $false)]
[Switch]$IncludeOptionalMiners = $true, # If true use the miners in the 'OptionalMiners' directory
[Parameter(Mandatory = $false)]
[Switch]$IncludeRegularMiners = $true, # If true use the miners in the 'Miners' directory
[Parameter(Mandatory = $false)]
[Switch]$IncludeLegacyMiners = $true, # If true use the miners in the 'LegacyMiners' directory (Miners based on the original MultiPoolMiner format)
[Parameter(Mandatory = $false)]
[Int]$Interval = 240, # Average cycle loop duration (seconds)
[Parameter(Mandatory = $false)]
[Switch]$LogBalanceAPIResponse = $false, # If true NemosMiner will log the pool balance API data
[Parameter(Mandatory = $false)]
[String[]]$LogToFile = @("Info", "Warn", "Error", "Verbose", "Debug"), # Log level detail to be written to log file, see Write-Message function
[Parameter(Mandatory = $false)]
[String[]]$LogToScreen = @("Info", "Warn", "Error", "Verbose", "Debug"), # Log level detail to be written to screen, see Write-Message function
[Parameter(Mandatory = $false)]
[ValidateRange(0, 1)]
[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]$MinDataSamples = 20, # Minimum number of hash rate samples required to store hash rate
[Parameter(Mandatory = $false)]
[Hashtable]$MinDataSamplesAlgoMultiplier = @{ "X25r" = 3 }, # Per algo multiply MinDataSamples by this value
[Parameter(Mandatory = $false)]
[Switch]$MinerInstancePerDeviceModel = $true, # If true NemosMiner will create separate miner instances per device model. This will increase profitability.
[Parameter(Mandatory = $false)]
[Int]$MinerSet = 1, # 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;
[Parameter(Mandatory = $false)]
[String]$MiningPoolHubAPIKey = "", # MiningPoolHub API Key (required to retrieve balance information)
[Parameter(Mandatory = $false)]
[String]$MiningPoolHubUserName = "Nemo", # MiningPoolHub UserName
[Parameter(Mandatory = $false)]
[Switch]$MineWhenIdle = $false, # If true NemosMiner will start mining only if system is idle for $IdleSec seconds
[Parameter(Mandatory = $false)]
[Int]$MinWorker = 10, # 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 = "", # Monitoring server hostname, default "https://nemosminer.com"
[Parameter(Mandatory = $false)]
[String]$MonitoringUser = "", # Unique monitoring user ID
[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)]
[Switch]$NiceHashWalletIsInternal = $false, # Set to $true if NiceHashWallet is a NiceHash internal wallet (lower pool fees)
[Parameter(Mandatory = $false)]
[String]$NiceHashWallet = "", # NiceHash wallet, if left empty $Wallet is used
[Parameter(Mandatory = $false)]
[String]$NiceHashOrganizationId = "", # NiceHash Organization Id (required to retrieve balance information)
[Parameter(Mandatory = $false)]
[Switch]$OpenFirewallPorts = $true, # If true NemosMiner 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)]
[String]$PoolsConfigFile = ".\Config\PoolsConfig.json", # PoolsConfig file name
[Parameter(Mandatory = $false)]
[Uint16]$PoolBalancesUpdateInterval = 15, #NemosMiner will udate balances every n minutes to limit pool API requests. Allowed values 0 - 999 minutes. 0 will disable gathering pool balances
[Parameter(Mandatory = $false)]
[String[]]$PoolName = @("Blockmasters", "MiningPoolHub", "NiceHash", "ZergPoolCoins", "ZPool"),
[Parameter(Mandatory = $false)]
[Int]$PoolTimeout = 20, # Time (in seconds) until NemosMiner 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]$PowerUsage = @{ }, # Static power usage per device in W, e.g. @{ "GPU#03" = 25, "GPU#04 = 55" } (in case HWiNFO cannot read power usage)
[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 usage 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 = "nemos", # 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 West", # Used to determine pool nearest to you.
[Parameter(Mandatory = $false)]
[Switch]$ReportToServer = $false,
[Parameter(Mandatory = $false)]
[Double]$RunningMinerGainPct = 12, # As lang as no other miner has earning/profit that are n % higher than the current miner it will not switch
[Parameter(Mandatory = $false)]
[Switch]$ShowAccuracy = $true, # Show pool data accuracy column in miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowAllMiners = $false, # Always show all miners in miner overview (if $false, only the best miners will be shown except when in benchmark / powerusage measurement)
[Parameter(Mandatory = $false)]
[Switch]$ShowEarning = $true, # Show miner earning column in miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowEarningBias = $true, # Show miner earning bias column in miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowMinerFee = $true, # Show miner fee column in miner overview (if fees are available, t.b.d. in miner files, Property '[Double]Fee')
[Parameter(Mandatory = $false)]
[String]$ShowMinerWindows = "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]$ShowMinerWindowsNormalWhenBenchmarking = $true, # If true Miner window is shown normal when benchmarking (recommended to better see miner messages)
[Parameter(Mandatory = $false)]
[Switch]$ShowPoolBalances = $false, # Display pool balances & earnings information in text window, requires BalancesTrackerPollInterval > 0
[Parameter(Mandatory = $false)]
[Switch]$ShowPoolFee = $true, # Show pool fee column in miner overview
[Parameter(Mandatory = $false)]
[Switch]$ShowPowerCost = $true, # Show Power cost column in miner overview (if power price is available, see PowerPricekWh)
[Parameter(Mandatory = $false)]
[Switch]$ShowProfit = $true, # Show miner profit column in miner overview (if power price is available, see PowerPricekWh)
[Parameter(Mandatory = $false)]
[Switch]$ShowProfitBias = $true, # Show miner profit bias column in miner overview (if power price is available, see PowerPricekWh)
[Parameter(Mandatory = $false)]
[Switch]$ShowPowerUsage = $true, # Show Power usage column in miner overview (if power price is available, see PowerPricekWh)
[Parameter(Mandatory = $false)]
[String]$SnakeTailExe = ".\Utils\SnakeTail.exe", # Path to optional external log reader (SnakeTail) [https://github.com/snakefoot/snaketail-net], leave empty to disable
[Parameter(Mandatory = $false)]
[String]$SnakeTailConfig = ".\Utils\NemosMiner_LogReader.xml", # Path to SnakeTail session config file
[Parameter(Mandatory = $false)]
[Switch]$SSL = $false, # If true NemosMiner will prefer pools which support SSL connections
[Parameter(Mandatory = $false)]
[Switch]$StartGUIMinimized = $true,
[Parameter(Mandatory = $false)]
[Switch]$StartPaused = $false, # If true NemosMiner will start background jobs (Earnings Tracker etc.), but will not mine
[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]$UsemBTC = $true, # If true NemosMiner will display BTC values in milli BTC
[Parameter(Mandatory = $false)]
[Switch]$UseMinerTweaks = $false, # If true NemosMiner 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
[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 algo & 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 = $false, # If true pools (currently ZergPool only) will use anycast for best network performance and ping times
[Parameter(Mandatory = $false)]
[Int[]]$WarmupTimes = @(0, 15), # First value: Time (in seconds) until miner must send stable hashrates (default 0, accept first sample), second value: Time (in seconds) the miner is allowed to get ready, e.g. wait for pool, to compile the binaries or to get the API ready (default 15); if miner does not send valid samples in time it will get stopped and marked as failed
[Parameter(Mandatory = $false)]
[Hashtable]$Wallets = @{ "BTC" = "1QGADhdMRpp9Pk5u5zG1TrHKRrdK5R81TE"; "ETC" = "0x7CF99ec9029A98AFd385f106A93977D8105Fec0f"; "ETH" = "0x92e6F22C1493289e6AD2768E1F502Fc5b414a287" },
[Parameter(Mandatory = $false)]
[Switch]$Watchdog = $true, # if true NemosMiner will automatically put pools and/or miners temporarily on hold it they fail a few times in 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 = "ID=testing"
)
Set-Location (Split-Path $MyInvocation.MyCommand.Path)
@"
NemosMiner
Copyright (c) 2018-$((Get-Date).Year) Nemo, MrPlus & UselessGuru
This is free software, and you are welcome to redistribute it
under certain conditions.
https://github.com/Minerx117/NemosMiner/blob/master/LICENSE
"@
Write-Host "`nCopyright and license notices must be preserved.`n" -ForegroundColor Yellow
# Load Branding
$Global:Branding = [PSCustomObject]@{
LogoPath = "https://raw.githubusercontent.com/Minerx117/UpDateData/master/NM.png"
BrandName = "NemosMiner"
BrandWebSite = "https://nemosminer.com"
ProductLabel = "NemosMiner"
Version = [System.Version]"3.9.9.62"
}
If (-not (Test-Path -Path ".\Cache" -PathType Container)) { New-Item -Path . -Name "Cache" -ItemType Directory -ErrorAction Ignore | Out-Null }
If ($PSVersiontable.PSVersion -lt [System.Version]"7.0.0") {
Write-Host "`nUnsupported PowerShell version $($PSVersiontable.PSVersion.ToString()) detected.`n$($Branding.BrandName) requires at least PowerShell version 7.0.0 which can be downloaded from https://github.com/PowerShell/powershell/releases.`n`n" -ForegroundColor Red
Start-Sleep -Seconds 30
Exit
}
Try {
Add-Type -Path ".\Cache\~OpenCL_$($PSVersionTable.PSVersion.ToString()).dll" -ErrorAction Stop
}
Catch {
Remove-Item ".\Cache\~OpenCL_$($PSVersionTable.PSVersion.ToString()).dll" -Force -ErrorAction Ignore
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 {
Remove-Item ".\Cache\~CPUID_$($PSVersionTable.PSVersion.ToString()).dll" -Force -ErrorAction Ignore
Add-Type -Path ".\Includes\CPUID.cs" -OutputAssembly ".\Cache\~CPUID_$($PSVersionTable.PSVersion.ToString()).dll"
Add-Type -Path ".\Cache\~CPUID_$($PSVersionTable.PSVersion.ToString()).dll"
}
# Create directories
If (-not (Test-Path -Path ".\Config" -PathType Container)) { New-Item -Path . -Name "Config" -ItemType Directory | Out-Null }
If (-not (Test-Path -Path ".\Logs" -PathType Container)) { New-Item -Path . -Name "Logs" -ItemType Directory | Out-Null }
# Initialize global variables
New-Variable Config ([Hashtable]::Synchronized( @{ } )) -Scope "Global" -Force -ErrorAction Stop
New-Variable Stats ([Hashtable]::Synchronized( @{ } )) -Scope "Global" -Force -ErrorAction Stop
New-Variable Variables ([Hashtable]::Synchronized( @{ } )) -Scope "Global" -Force -ErrorAction Stop
$Variables.Miners = [Miner[]]
$Variables.Pools = [Miner]::Pools
# Expand paths
$Variables.MainPath = (Split-Path $MyInvocation.MyCommand.Path)
$Variables.LogFile = "$($Variables.MainPath)\Logs\NemosMiner_$(Get-Date -Format "yyyy-MM-dd").log"
$Variables.ConfigFile = "$($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($ConfigFile))"
$Variables.PoolsConfigFile = "$($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($PoolsConfigFile))"
$Variables.BalancesTrackerConfigFile = "$($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Config.BalancesTrackerConfigFile))"
$Variables.CurrentProduct = $Branding.ProductLabel
$Variables.CurrentVersion = $Branding.Version
# Get command line parameters, required in Read-Config
$AllCommandLineParameters = [Ordered]@{ }
$MyInvocation.MyCommand.Parameters.Keys | Where-Object { $_ -notin @("ConfigFile", "PoolsConfigFile", "BalancesTrackerConfigFile", "Verbose", "Debug", "ErrorAction", "WarningAction", "InformationAction", "ErrorVariable", "WarningVariable", "InformationVariable", "OutVariable", "OutBuffer", "PipelineVariable") } | Sort-Object | ForEach-Object {
$AllCommandLineParameters.$_ = Get-Variable $_ -ValueOnly -ErrorAction SilentlyContinue
If ($AllCommandLineParameters.$_ -is [Switch]) { $AllCommandLineParameters.$_ = [Boolean]$AllCommandLineParameters.$_ }
}
$Variables.AllCommandLineParameters = $AllCommandLineParameters
# Load algorithm list
$Variables.Algorithms = Get-Content -Path ".\Includes\Algorithms.json" -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore
If (-not $Variables.Algorithms) {
Write-Message -Level Error "Terminating Error - Cannot continue!`nFile '$($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath('.\Includes\Algorithms.json'))' is not a valid JSON file. Please restore it from your original download." -Console
Start-Sleep -Seconds 10
Exit
}
# Load regions list
$Variables.Regions = Get-Content -Path ".\Includes\Regions.json" -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore
If (-not $Variables.Regions) {
Write-Message -Level Error "Terminating Error - Cannot continue!`nFile '$($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath('.\Includes\Regions.json'))' is not a valid JSON file. Please restore it from your original download." -Console
Start-Sleep -Seconds 10
Exit
}
# Verify pool data
Try { [Void](Get-Content -Path ".\Includes\PoolData.json" -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore) }
Catch {
Write-Message -Level Error "Terminating Error - Cannot continue!`nFile '$($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath('.\Includes\PoolData.json'))' is not a valid JSON file. Please restore it from your original download." -Console
Start-Sleep -Seconds 10
Exit
}
# Verify coin name data
Try { [Void](Get-Content -Path ".\Includes\CoinNames.json" -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore) }
Catch {
Write-Message -Level Error "Terminating Error - Cannot continue!`nFile '$($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath('.\Includes\CoinNames.json'))' is not a valid JSON file. Please restore it from your original download." -Console
Start-Sleep -Seconds 10
Exit
}
# Read configuration
Read-Config -ConfigFile $Variables.ConfigFile
$AllCommandLineParameters | ForEach-Object {
Remove-Variable $_ -ErrorAction SilentlyContinue
}
# Start transcript log
If ($Config.Transcript -eq $true) { Start-Transcript ".\Logs\NemosMiner_$(Get-Date -Format "yyyy-MM-dd_HH-mm-ss").log" }
Write-Message -Level Info "Starting $($Branding.ProductLabel)® v$($Variables.CurrentVersion) © 2017-$((Get-Date).Year) Nemo, MrPlus and UselessGuru" -Console
If (-not $Variables.FreshConfig) { Write-Message -Level Info "Using configuration file '$($Variables.ConfigFile)'." -Console }
Write-Host ""
# Start Log reader (SnakeTail) [https://github.com/snakefoot/snaketail-net]
If ((Test-Path $Config.SnakeTailExe -PathType Leaf -ErrorAction Ignore) -and (Test-Path $Config.SnakeTailConfig -PathType Leaf -ErrorAction Ignore)) {
$Variables.SnakeTailConfig = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Config.SnakeTailConfig)
$Variables.SnakeTailExe = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Config.SnakeTailExe)
If (-not (Get-CimInstance CIM_Process | Where-Object CommandLine -EQ "`"$($Variables.SnakeTailExe)`" $($Variables.SnakeTailConfig)")) {
& "$($Variables.SnakeTailExe)" $Variables.SnakeTailConfig
}
}
#Prerequisites check
Write-Message -Level Verbose "Verifying pre-requisites..." -Console
$Prerequisites = @(
"$env:SystemRoot\System32\MSVCR120.dll",
"$env:SystemRoot\System32\VCRUNTIME140.dll",
"$env:SystemRoot\System32\VCRUNTIME140_1.dll"
)
If ($PrerequisitesMissing = @($Prerequisites | Where-Object { -not (Test-Path $_ -PathType Leaf) })) {
$PrerequisitesMissing | ForEach-Object { Write-Message -Level Warn "$_ is missing." -Console }
Write-Message -Level Error "Please install the required runtime modules. Download and extract" -Console
Write-Message -Level Error "https://github.com/Minerx117/Visual-C-Runtimes-All-in-One-Sep-2019/releases/download/sep2019/Visual-C-Runtimes-All-in-One-Sep-2019.zip" -Console
Write-Message -Level Error "and run 'install_all.bat'." -Console
Start-Sleep -Seconds 10
Exit
}
Else { Write-Message -Level Verbose "Pre-requisites check OK." -Console }
Remove-Variable PrerequisitesMissing, Prerequisites
# Check if new version is available
Get-NMVersion
Write-Host "Importing modules..." -ForegroundColor Yellow
Import-Module NetSecurity -ErrorAction SilentlyContinue
Import-Module Defender -ErrorAction SilentlyContinue
# Unblock files
If (Get-Item .\* -Stream Zone.*) {
Write-Host "Unblocking files that were downloaded from the internet..." -ForegroundColor Yellow
If (Get-Command "Unblock-File" -ErrorAction SilentlyContinue) { Get-ChildItem -Path . -Recurse | Unblock-File }
If ((Get-Command "Get-MpPreference" -ErrorAction Ignore) -and (Get-MpComputerStatus -ErrorAction Ignore) -and (Get-MpPreference).ExclusionPath -notcontains (Convert-Path .)) {
Start-Process "pwsh" "-Command Import-Module Defender; Add-MpPreference -ExclusionPath '$(Convert-Path .)'" -Verb runAs
}
}
# Update config file to include all new config items
If ($Variables.AllCommandLineParameters -and (-not $Config.ConfigFileVersion -or [System.Version]::Parse($Config.ConfigFileVersion) -lt $Variables.CurrentVersion )) {
Update-ConfigFile -ConfigFile $Variables.ConfigFile
}
If (Test-Path -Path .\Cache\VertHash.dat -PathType Leaf) {
Write-Message -Level Verbose "Verifying integrity of VertHash data file (.\Cache\VertHash.dat)..."
$VertHashDatCheckJob = Start-Job ([ScriptBlock]::Create("(Get-FileHash .\Cache\VertHash.dat).Hash -eq 'A55531E843CD56B010114AAF6325B0D529ECF88F8AD47639B6EDEDAFD721AA48'"))
}
Write-Message -Level Verbose "Loading device information..."
$Variables.SupportedDeviceVendors = @("AMD", "INTEL", "NVIDIA")
$Variables.Devices = [Device[]](Get-Device -Refresh)
$Variables.Devices | Where-Object { $_.Vendor -notin $Variables.SupportedDeviceVendors } | ForEach-Object { $_.State = [DeviceState]::Unsupported; $_.Status = "Disabled (Unsupported Vendor: '$($_.Vendor)')" }
$Variables.Devices | Where-Object Name -In $Config.ExcludeDeviceName | Where-Object { $_.State -NE [DeviceState]::Unsupported } | ForEach-Object { $_.State = [DeviceState]::Disabled; $_.Status = "Disabled (ExcludeDeviceName: '$($_.Name)')" }
# MinerInstancePerDeviceModel: Default to $true if more than one device model per vendor
If ($Variables.FreshConfig -eq $true) { $Config.MinerInstancePerDeviceModel = ($Variables.Devices | Group-Object Vendor | ForEach-Object { ($_.Group.Model | Sort-Object -Unique).Count } | Measure-Object -Maximum).Maximum -gt 1 }
Write-Host "Setting variables..." -ForegroundColor Yellow
$Variables.BrainJobs = @{ }
$Variables.IsLocalAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")
$Variables.Miners = [Miner[]]@()
$Variables.Pools = [Pool[]]@()
$Variables.ScriptStartTime = (Get-Date).ToUniversalTime()
$Variables.AvailableCommandLineParameters = @($AllCommandLineParameters.Keys | Sort-Object)
$Variables.MyIP = (Get-NetIPConfiguration | Where-Object IPv4DefaultGateway).IPv4Address.IPAddress
$Variables.DriverVersion = @{ }
$Variables.DriverVersion | Add-Member AMD ((($Variables.Devices | Where-Object { $_.Type -EQ "GPU" -and $_.Vendor -eq "AMD" }).OpenCL.DriverVersion | Select-Object -Index 0) -split ' ' | Select-Object -Index 0)
$Variables.DriverVersion | Add-Member NVIDIA ((($Variables.Devices | Where-Object { $_.Type -EQ "GPU" -and $_.Vendor -eq "NVIDIA" }).OpenCL.DriverVersion | Select-Object -Index 0) -split ' ' | Select-Object -Index 0)
$Variables.MiningStatus = $Variables.NewMiningStatus = "Stopped"
$Variables.Strikes = 3
$Variables.WatchdogTimers = @()
$Variables.StatStarts = @()
$Variables.PoolsLastUsed = @{}
If (Test-Path -Path ".\Logs\PoolsLastUsed.json" -PathType Leaf) { $Variables.PoolsLastUsed = Get-Content ".\Logs\PoolsLastUsed.json" -ErrorAction Ignore | ConvertFrom-Json -AsHashtable -ErrorAction Ignore }
If (Test-Path -Path ".\Logs\EarningsChartData.json" -PathType Leaf) { $Variables.EarningsChartData = Get-Content ".\Logs\EarningsChartData.json" -ErrorAction Ignore | ConvertFrom-Json -ErrorAction Ignore }
# Rename existing switching log
If (Test-Path -Path ".\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 ($env:CUDA_DEVICE_ORDER -ne 'PCI_BUS_ID') { $env:CUDA_DEVICE_ORDER = 'PCI_BUS_ID' } # Align CUDA id with nvidia-smi order
If ($env:GPU_FORCE_64BIT_PTR -ne 1) { $env:GPU_FORCE_64BIT_PTR = 1 } # For AMD
If ($env:GPU_MAX_HEAP_SIZE -ne 100) { $env:GPU_MAX_HEAP_SIZE = 100 } # For AMD
If ($env:GPU_USE_SYNC_OBJECTS -ne 1) { $env:GPU_USE_SYNC_OBJECTS = 1 } # For AMD
If ($env:GPU_MAX_ALLOC_PERCENT -ne 100) { $env:GPU_MAX_ALLOC_PERCENT = 100 } # For AMD
If ($env:GPU_SINGLE_ALLOC_PERCENT -ne 100) { $env:GPU_SINGLE_ALLOC_PERCENT = 100 } # For AMD
If ($env:GPU_MAX_WORKGROUP_SIZE -ne 256) { $env:GPU_MAX_WORKGROUP_SIZE = 256 } # For AMD
If ($Config.AutoStart) {
$Variables.NewMiningStatus = If ($Config.StartPaused) { "Paused" } Else { "Running" }
# Trigger start mining in TimerUITick
$Variables.RestartCycle = $true
}
If (Test-Path -Path .\Cache\VertHash.dat -PathType Leaf) {
If ($VertHashDatCheckJob | Wait-Job -Timeout 60 | Receive-Job -Wait -AutoRemoveJob) {
Write-Message -Level Verbose "VertHash data file integrity check: OK."
}
Else {
Remove-Item -Path .\Cache\VertHash.dat -Force -ErrorAction Ignore
Write-Message -Level Warn "VertHash data file (.\Cache\VertHash.dat) is corrupt -> file deleted. It will be recreated by the miners if needed."
}
}
If ($Config.WebGUI -eq $true) { Initialize-API }
Function Get-Chart {
Function Get-NextColor {
Param(
[Parameter(Mandatory = $true)]
[Byte[]]$Colors,
[Parameter(Mandatory = $true)]
[Int[]]$Factors
)
# Apply change Factor
0, 1, 2, 3 | ForEach-Object {
$Colors[$_] = [math]::Abs(($Colors[$_] + $Factors[$_]) % 256)
}
$Colors
}
If (Test-Path -Path ".\Logs\DailyEarnings.csv" -PathType Leaf) {
$DatasourceRaw = Import-Csv ".\Logs\DailyEarnings.csv" -ErrorAction Ignore
$DatasourceRaw | ForEach-Object { $_.Date = [DateTime]::parseexact($_.Date, "yyyy-MM-dd", $null) }
$Datasource = $DatasourceRaw | Where-Object Date -le (Get-Date).AddDays(-1)
$Datasource = $Datasource | Where-Object Date -in @($Datasource.Date | Sort-Object -Unique | Select-Object -Last 7)
$Datasource | ForEach-Object { $_.DailyEarnings = [Double]($_.DailyEarnings) * $Variables.Rates.($_.Currency).($Config.Currency) }
$Datasource = $Datasource | Select-Object *, @{ Name = "DaySum"; Expression = { $Date = $_.Date; ((($Datasource | Where-Object { $_.Date -eq $Date }).DailyEarnings) | Measure-Object -Sum).Sum } }
$ChartTitle = New-Object System.Windows.Forms.DataVisualization.Charting.Title
$ChartTitle.Text = ("Earnings Tracker: Earnings of the past 7 active days")
$ChartTitle.Font = [System.Drawing.Font]::new("Arial", 10)
$ChartTitle.Alignment = "TopCenter"
$EarningsChart1.Titles.Clear()
$EarningsChart1.Titles.Add($ChartTitle)
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
$ChartArea.BackColor = [System.Drawing.Color]::FromArgb(255, 32, 50, 50) #"#2B3232"
$ChartArea.BackSecondaryColor = [System.Drawing.Color]::FromArgb(255, 119, 126, 126) #"#777E7E"
$ChartArea.BackGradientStyle = 3
$ChartArea.AxisX.LabelStyle.Enabled = $false
$ChartArea.AxisX.Enabled = 2
$ChartArea.AxisX.MajorGrid.Enabled = $false
$ChartArea.AxisY.MajorGrid.Enabled = $true
$ChartArea.AxisY.MajorGrid.LineColor = [System.Drawing.Color]::FromArgb(255, 255, 255, 255) #"#FFFFFF"
$ChartArea.AxisY.LabelAutoFitStyle = $ChartArea.AxisY.labelAutoFitStyle - 4
$ChartArea.AxisY.Interval = [Math]::Ceiling(($Datasource.DaySum | Measure-Object -Maximum).Maximum / 4)
$EarningsChart1.ChartAreas.Clear()
$EarningsChart1.ChartAreas.Add($ChartArea)
$EarningsChart1.Series.Clear()
[void]$EarningsChart1.Series.Add("TotalEarning")
$EarningsChart1.Series["TotalEarning"].ChartType = "Column"
$EarningsChart1.Series["TotalEarning"].BorderWidth = 3
$EarningsChart1.Series["TotalEarning"].ChartArea = "ChartArea1"
$EarningsChart1.Series["TotalEarning"].Color = [System.Drawing.Color]::FromArgb(255, 255, 255, 255) #"FFFFFF"
$EarningsChart1.Series["TotalEarning"].label = "#VALY{N3}"
$EarningsChart1.Series["TotalEarning"].ToolTip = "#VALX: #VALY $($Config.Currency)"
$Datasource | Select-Object Date, DaySum -Unique | ForEach-Object { $EarningsChart1.Series["TotalEarning"].Points.addxy( $_.Date.ToShortDateString() , ("{0:N5}" -f $_.DaySum)) | Out-Null }
$EarningsChart1.BringToFront()
$Datasource = $DatasourceRaw | Where-Object Date -eq (Get-Date).Date | Where-Object DailyEarnings -gt 0 | Sort-Object DailyEarnings -Descending
$Datasource | ForEach-Object { $_.DailyEarnings = [Double]($_.DailyEarnings) * $Variables.Rates.($_.Currency).($Config.Currency) }
$ChartTitle = New-Object System.Windows.Forms.DataVisualization.Charting.Title
$ChartTitle.Text = ("Todays earnings per pool")
$ChartTitle.Font = [System.Drawing.Font]::new("Arial", 10)
$ChartTitle.Alignment = "TopCenter"
$EarningsChart2.Titles.Clear()
$EarningsChart2.Titles.Add($ChartTitle)
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
$ChartArea.BackColor = [System.Drawing.Color]::FromArgb(255, 32, 50, 50) #"#2B3232"
$ChartArea.BackSecondaryColor = [System.Drawing.Color]::FromArgb(255, 119, 126, 126) #"#777E7E"
$ChartArea.BackGradientStyle = 3
$ChartArea.AxisX.LabelStyle.Enabled = $false
$ChartArea.AxisX.Enabled = 2
$ChartArea.AxisX.MajorGrid.Enabled = $false
$ChartArea.AxisY.MajorGrid.Enabled = $true
$ChartArea.AxisY.MajorGrid.LineColor = [System.Drawing.Color]::FromArgb(255, 255, 255, 255) #"#FFFFFF"
$ChartArea.AxisY.LabelAutoFitStyle = $ChartArea.AxisY.labelAutoFitStyle - 4
$ChartArea.AxisY.Interval = [Math]::Ceiling(($Datasource.DailyEarnings | Measure-Object -Sum).Sum / 4)
$EarningsChart2.ChartAreas.Clear()
$EarningsChart2.ChartAreas.Add($ChartArea)
$EarningsChart2.Series.Clear()
$Colors = @(255, 255, 255, 255) #"FFFFFF"
ForEach ($Pool in ($Datasource.Pool)) {
$Colors = (Get-NextColor -Colors $Colors -Factors -0, -20, -20, -20)
[void]$EarningsChart2.Series.Add($Pool)
$EarningsChart2.Series[$Pool].ChartType = "StackedColumn"
$EarningsChart2.Series[$Pool].BorderWidth = 1
$EarningsChart2.Series[$Pool].BorderColor = [System.Drawing.Color]::FromArgb(255, 119, 126 ,126) #"#FFFFFF"
$EarningsChart2.Series[$Pool].ChartArea = "ChartArea1"
$EarningsChart2.Series[$Pool].Color = [System.Drawing.Color]::FromArgb($Colors[0], $Colors[1], $Colors[2], $Colors[3])
$EarningsChart2.Series[$Pool].ToolTip = "#SERIESNAME: #VALY $($Config.Currency)"
$Datasource | Where-Object { $_.Pool -eq $Pool } | ForEach-Object { $EarningsChart2.Series[$Pool].Points.addxy( $_.Pool , ("{0:N3}" -f $_.DailyEarnings)) | Out-Null }
}
$EarningsChart2.BringToFront()
}
}
Function Update-TabControl {
Switch ($TabControl.SelectedTab.Text) {
"Run" {
If ($Variables.Miners) {
$RunningMinersDGV.DataSource = $Variables.Miners | Where-Object { $_.Status -eq "Running" } | Select-Object @(
@{ Name = "Device(s)"; Expression = { $_.DeviceName -join "; " } },
@{ Name = "Miner"; Expression = { $_.Info } },
@{ Name = "Account"; Expression = { ($_.Workers.Pool.User | Select-Object -Unique | ForEach-Object { $_ -split '\.' | Select-Object -Index 0 } | Select-Object -Unique) -join ' & ' } },
@{ Name = "Earning $($Config.Currency)/day"; Expression = { If (-not [Double]::IsNaN($_.Earning)) { ($_.Earning * $Variables.Rates.BTC.($Config.Currency)).ToString("N3") } Else { "Unknown" } } },
@{ Name = "Profit $($Config.Currency)/day"; Expression = { If ($Variables.CalculatePowerCost -and -not [Double]::IsNaN($_.Profit)) { ($_.Profit * $Variables.Rates.BTC.($Config.Currency)).ToString("N3") } Else { "Unknown" } } },
@{ Name = "Pool"; Expression = { ($_.Workers.Pool | ForEach-Object { (@(@($_.Name | Select-Object) + @($_.Coin | Select-Object))) -join '-' }) -join ' & ' } },
@{ Name = "Hashrate"; Expression = { If ($_.Speed_Live -contains $null) { ($_.Speed_Live | ForEach-Object { "$($_ | ConvertTo-Hash)/s" -replace "\s+", " " }) -join ' & ' } Else { ($_.Workers.Speed | ForEach-Object { "$($_ | ConvertTo-Hash)/s" -replace "\s+", " " }) -join ' & ' } } },
@{ Name = "Active (hhh:mm:ss)"; Expression = { "{0}:{1:mm}:{1:ss}" -f [math]::floor(((Get-Date).ToUniversalTime() - $_.BeginTime).TotalDays * 24), ((Get-Date).ToUniversalTime() - $_.BeginTime) } },
@{ Name = "Total Active (hhh:mm:ss)"; Expression = { "{0}:{1:mm}:{1:ss}" -f [math]::floor($_.TotalMiningDuration.TotalDays * 24), $_.TotalMiningDuration } }
) | Sort-Object "Device(s)" | Out-DataTable
$RunningMinersDGV.ClearSelection()
If ($RunningMinersDGV.Columns) {
$RunningMinersDGV.Columns[0].FillWeight = 75
$RunningMinersDGV.Columns[1].FillWeight = 225
$RunningMinersDGV.Columns[2].FillWeight = 150
$RunningMinersDGV.Columns[3].FillWeight = 50
$RunningMinersDGV.Columns[4].FillWeight = 50
$RunningMinersDGV.Columns[5].FillWeight = 100
$RunningMinersDGV.Columns[6].FillWeight = 85
$RunningMinersDGV.Columns[7].FillWeight = 65
$RunningMinersDGV.Columns[8].FillWeight = 65
}
$LabelRunningMiners.Text = "Running Miners - Updated $((Get-Date).ToString())"
}
Else { $LabelRunningMiners.Text = "Waiting for data..." }
}
"Earnings" {
Get-Chart
If ($Variables.Balances) {
$EarningsDGV.DataSource = $Variables.Balances.Values | Select-Object @(
@{ Name = "Pool"; Expression = { "$($_.Pool -replace 'Internal$', ' (Internal)' -replace 'External', ' (External)') [$($_.Currency)]" } },
@{ Name = "Balance ($($Config.Currency))"; Expression = { "{0:N8}" -f ($_.Balance * $Variables.Rates.($_.Currency).($Config.Currency)) } },
@{ Name = "Avg. $($Config.Currency)/day"; Expression = { "{0:N8}" -f ($_.AvgDailyGrowth * $Variables.Rates.($_.Currency).($Config.Currency)) } },
@{ Name = "$($Config.Currency) in 1h"; Expression = { "{0:N6}" -f ($_.Growth1 * $Variables.Rates.($_.Currency).($Config.Currency)) } },
@{ Name = "$($Config.Currency) in 6h"; Expression = { "{0:N6}" -f ($_.Growth6 * $Variables.Rates.($_.Currency).($Config.Currency)) } },
@{ Name = "$($Config.Currency) in 24h"; Expression = { "{0:N6}" -f ($_.Growth24 * $Variables.Rates.($_.Currency).($Config.Currency)) } },
@{ Name = "Est. Pay Date"; Expression = { If ($_.EstimatedPayDate -is [DateTime]) { $_.EstimatedPayDate.ToShortDateString() } Else { $_.EstimatedPayDate } } },
@{ Name = "PayoutThreshold"; Expression = { "$($_.PayoutThreshold) $($_.PayoutThresholdCurrency) ($('{0:P1}' -f $($_.Balance / ($_.PayoutThreshold * $Variables.Rates.($_.PayoutThresholdCurrency).($_.Currency)))))" } }
) | Sort-Object Pool | Out-DataTable
$EarningsDGV.ClearSelection()
If ($EarningsDGV.Columns) {
$EarningsDGV.Columns[0].FillWeight = 140
$EarningsDGV.Columns[1].FillWeight = 90
$EarningsDGV.Columns[2].FillWeight = 90
$EarningsDGV.Columns[3].FillWeight = 75
$EarningsDGV.Columns[4].FillWeight = 75
$EarningsDGV.Columns[5].FillWeight = 75
$EarningsDGV.Columns[6].FillWeight = 80
$EarningsDGV.Columns[7].FillWeight = 100
}
$LabelEarnings.Text = "Earnings statistics per pool - Updated $((Get-ChildItem -Path ".\Logs\DailyEarnings.csv" -ErrorAction Ignore).LastWriteTime.ToString())"
}
Else { $LabelEarnings.Text = "Waiting for data..." }
}
"Switching Log" {
CheckBoxSwitching_Click
}
"Rig Monitoring" {
If ($Variables.Workers) {
$WorkersDGV.DataSource = $Variables.Workers | Select-Object @(
@{ Name = "Worker"; Expression = { $_.worker } },
@{ Name = "Status"; Expression = { $_.status } },
@{ Name = "Last seen"; Expression = { "$($_.timesincelastreport -replace '^-')" } },
@{ Name = "Version"; Expression = { $_.version } },
@{ Name = "Est. Profit $($Config.Currency)/day"; Expression = { [decimal]($_.Profit * ($Variables.Rates.BTC.($Config.Currency))) } },
@{ Name = "Miner"; Expression = { $_.data.Name -join '; ' } },
@{ Name = "Pool"; Expression = { ($_.data.Pool -replace 'Internal$', ' (Internal)' -replace 'External', ' (External)' | ForEach-Object { $_ -split ',' -join ' & ' }) -join '; ' } },
@{ Name = "Algorithm"; Expression = { ($_.data.Algorithm | ForEach-Object { $_ -split ',' -join ' & ' }) -join '; ' } },
@{ Name = "Hashrate"; Expression = { If ($_.data.CurrentSpeed) { ($_.data.CurrentSpeed | ForEach-Object { ($_ -split ',' | ForEach-Object { "$($_ | ConvertTo-Hash)/s" -replace "\s+", " " } ) -join ' & ' }) } Else { "" } } },
@{ Name = "Benchmark Hashrate"; Expression = { If ($_.data.EstimatedSpeed) { ($_.data.EstimatedSpeed | ForEach-Object { ($_ -split ',' | ForEach-Object { "$($_ | ConvertTo-Hash)/s" -replace "\s+", " " } ) -join ' & ' }) -join '; ' } Else { "" } } }
) | Sort-Object "Worker" | Out-DataTable
$WorkersDGV.ClearSelection()
If ($WorkersDGV.Columns) {
$WorkersDGV.Columns[0].FillWeight = 75
$WorkersDGV.Columns[1].FillWeight = 60
$WorkersDGV.Columns[2].FillWeight = 80
$WorkersDGV.Columns[3].FillWeight = 80
$WorkersDGV.Columns[4].FillWeight = 80
$WorkersDGV.Columns[5].FillWeight = 150
$WorkersDGV.Columns[6].FillWeight = 120
$WorkersDGV.Columns[7].FillWeight = 150
$WorkersDGV.Columns[8].FillWeight = 125
}
# Set row color
ForEach ($Row in $WorkersDGV.Rows) {
$Row.DefaultCellStyle.Backcolor = Switch ($Row.DataBoundItem.Status) {
"Offline" { [System.Drawing.Color]::FromArgb(255, 213, 142, 176) }
"Paused" { [System.Drawing.Color]::FromArgb(255, 247, 252, 168) }
"Running" { [System.Drawing.Color]::FromArgb(255, 127, 191, 144) }
Default { [System.Drawing.Color]::FromArgb(255, 255, 255, 255) }
}
}
$LabelWorkers.Text = "Worker Status - Updated $($Variables.WorkersLastUpdated.ToString())"
}
Else { $LabelWorkers.Text = "Worker Status - no workers" }
}
"Benchmarks" {
If ($Variables.Miners) {
If ($Variables.CalculatePowerCost -and (-not $Config.IgnorePowerCost)) { $SortBy = "Profit" } Else { $SortBy = "Earning" }
$BenchmarksDGV.DataSource = $Variables.Miners | Where-Object Available -EQ $true | Select-Object @(
@{ Name = "Miner"; Expression = { $_.Name } },
@{ Name = "Device(s)"; Expression = { $_.DeviceName -join '; ' } },
@{ Name = "Algorithm"; Expression = { $_.Algorithm -join ' & ' } },
@{ Name = "PowerUsage"; Expression = { If ($_.MeasurePowerUsage) { "Measuring" } Else { "$($_.PowerUsage.ToString("N3")) W" } } },
@{ Name = "Hashrate"; Expression = { ($_.Workers.Speed | ForEach-Object { If (-not [Double]::IsNaN($_)) { "$($_ | ConvertTo-Hash)/s" -replace '\s+', ' ' } Else { "Benchmarking" } }) -join ' & ' } },
@{ Name = "Earning $($Config.Currency)/day"; Expression = { If (-not [Double]::IsNaN($_.Earning)) { ($_.Earning * $Variables.Rates.BTC.($Config.Currency)).ToString("N3") } Else { "Unknown" } } },
@{ Name = "Profit $($Config.Currency)/day"; Expression = { If ($Variables.CalculatePowerCost -and -not [Double]::IsNaN($_.Profit)) { ($_.Profit * $Variables.Rates.BTC.($Config.Currency)).ToString("N3") } Else { "Unknown" } } },
@{ Name = "Pool"; Expression = { ($_.Workers.Pool | ForEach-Object { (@(@($_.Name | Select-Object) + @($_.Coin | Select-Object))) -join '-' }) -join ' & ' } }
) | Sort-Object "$SortBy $($Config.Currency)/day" -Descending | Out-DataTable
Remove-Variable SortBy
$BenchmarksDGV.ClearSelection()
If ($BenchmarksDGV.Columns) {
$BenchmarksDGV.Columns[0].FillWeight = 220
$BenchmarksDGV.Columns[1].FillWeight = 80
$BenchmarksDGV.Columns[2].FillWeight = 90
$BenchmarksDGV.Columns[3].FillWeight = 70
$BenchmarksDGV.Columns[4].FillWeight = 100
$BenchmarksDGV.Columns[5].FillWeight = 55
$BenchmarksDGV.Columns[6].FillWeight = 55
$BenchmarksDGV.Columns[7].FillWeight = 125
}
$LabelBenchmarks.Text = "Benchmark data read from stats - Updated $((Get-Date).ToString())"
}
Else { $LabelBenchmarks.Text = "Waiting for data..." }
}
}
}
Function Global:TimerUITick {
$TimerUI.Enabled = $false
$Variables.LogFile = "$($Variables.MainPath)\Logs\NemosMiner_$(Get-Date -Format "yyyy-MM-dd").log"
# If something (pause button, idle timer, WebGUI/config) has set the RestartCycle flag, stop and start mining to switch modes immediately
If ($Variables.RestartCycle) {
If ($Variables.NewMiningStatus -eq "Stopped") {
$ButtonPause.Enabled = $false
$ButtonStart.Enabled = $false
$ButtonStop.Enabled = $false
Stop-Mining
Stop-IdleMining
Stop-BrainJob
Stop-BalancesTracker
$Variables.Summary = ""
$LabelMiningStatus.Text = "Stopped | $($Branding.ProductLabel) $($Variables.CurrentVersion)"
$LabelMiningStatus.ForeColor = [System.Drawing.Color]::Red
Write-Message -Level Info "$($Branding.ProductLabel) is idle." -Console
$ButtonPause.Enabled = $true
$ButtonStart.Enabled = $true
}
ElseIf ($Variables.NewMiningStatus -eq "Paused") {
If ($Variables.MiningStatus -ne "Paused") {
$ButtonPause.Enabled = $false
$ButtonStart.Enabled = $false
$ButtonStop.Enabled = $false
If ($Variables.MiningStatus -eq "Running") {
Stop-Mining
Stop-IdleMining
}
Else {
Initialize-Application
Start-BrainJob
Start-BalancesTracker
}
Write-Message -Level Info "Mining is paused. BrainPlus and Earning tracker running." -Console
$ButtonStop.Enabled = $true
$ButtonStart.Enabled = $true
$LabelMiningStatus.Text = "Paused | $($Branding.ProductLabel) $($Variables.CurrentVersion)"
$LabelMiningStatus.ForeColor = [System.Drawing.Color]::Blue
$TimerUI.Stop
}
}
ElseIf ($Variables.NewMiningStatus -eq "Running") {
$Variables.UIStyle = $Config.UIStyle
$Variables.ShowAllMiners = $Config.ShowAllMiners
$Variables.ShowPoolBalances = $Config.ShowPoolBalances
$ButtonStop.Enabled = $true
$ButtonStart.Enabled = $false
$ButtonPause.Enabled = $true
If ($Variables.MiningStatus -ne "Running") {
Write-Host "`nMining processes started."
Initialize-Application
Start-BrainJob
Start-BalancesTracker
}
If ($Config.MineWhenIdle) {
Stop-Mining
If (-not $Variables.IdleRunspace) { Start-IdleMining }
}
Else {
Stop-IdleMining
Start-Mining
$ButtonStop.Enabled = $true
$ButtonPause.Enabled = $true
$LabelMiningStatus.Text = "Running | $($Branding.ProductLabel) $($Variables.CurrentVersion)"
$LabelMiningStatus.ForeColor = [System.Drawing.Color]::Green
}
}
$Variables.RestartCycle = $false
$Variables.MiningStatus = $Variables.NewMiningStatus
}
If ($Variables.RefreshNeeded -and $Variables.MiningStatus -eq "Running") {
$host.UI.RawUI.WindowTitle = $MainForm.Text = "$($Branding.ProductLabel) $($Variables.CurrentVersion) Runtime: {0:dd} days {0:hh} hrs {0:mm} mins Path: $($Variables.Mainpath)" -f ([TimeSpan]((Get-Date).ToUniversalTime() - $Variables.ScriptStartTime))
If (-not ($Variables.Miners | Where-Object Status -eq "Running")) { Write-Message "No miners running. Waiting for next cycle." }
If ($Variables.EndLoop) {
# Refresh selected tab
Update-TabControl
$LabelEarningsDetails.Lines = @($Variables.Summary -replace "<br>|( )+", "`n" -replace " / ", "/" -split "`n")
Clear-Host
# Get and display earnings stats
If ($Variables.Balances -and $Variables.ShowPoolBalances) {
$Variables.Balances.Values | ForEach-Object {
If ($_.Currency -eq "BTC" -and $Config.UsemBTC) { $Currency = "mBTC"; $mBTCfactor = 1000 } Else { $Currency = $_.Currency; $mBTCfactor = 1 }
Write-Host "$($_.Pool -replace 'Internal$', ' (Internal Wallet)' -replace 'External$', ' (External Wallet)') [$($_.Wallet)]" -BackgroundColor Green -ForegroundColor Black
Write-Host "Earned last hour: $(($_.Growth1 * $mBTCfactor).ToString('N8')) $Currency / $(($_.Growth1 * $Variables.Rates.($_.Currency).($Config.Currency)).ToString('N8')) $($Config.Currency)"
Write-Host "Earned last 24 hours: $(($_.Growth24 * $mBTCfactor).ToString('N8')) $Currency / $(($_.Growth24 * $Variables.Rates.($_.Currency).($Config.Currency)).ToString('N8')) $($Config.Currency)"
Write-Host "Earned last 7 days: $(($_.Growth168 * $mBTCfactor).ToString('N8')) $Currency / $(($_.Growth168 * $Variables.Rates.($_.Currency).($Config.Currency)).ToString('N8')) $($Config.Currency)"
Write-Host "≈ average / hour: $(($_.AvgHourlyGrowth * $mBTCfactor).ToString('N8')) $Currency / $(($_.AvgHourlyGrowth * $Variables.Rates.($_.Currency).($Config.Currency)).ToString('N8')) $($Config.Currency)"
Write-Host "≈ average / day: $(($_.AvgDailyGrowth * $mBTCfactor).ToString('N8')) $Currency / $(($_.AvgDailyGrowth * $Variables.Rates.($_.Currency).($Config.Currency)).ToString('N8')) $($Config.Currency)"
Write-Host "≈ average / week: $(($_.AvgWeeklyGrowth * $mBTCfactor).ToString('N8')) $Currency / $(($_.AvgWeeklyGrowth * $Variables.Rates.($_.Currency).($Config.Currency)).ToString('N8')) $($Config.Currency)"
Write-Host "Balance: " -NoNewline; Write-Host "$(($_.Balance * $mBTCfactor).ToString('N8')) $Currency / $(($_.Balance * $Variables.Rates.($_.Currency).($Config.Currency)).ToString('N8')) $($Config.Currency)" -ForegroundColor Yellow
Write-Host " $(($_.Balance / $_.PayoutThreshold * $mBTCFactor).ToString('P1')) of $($_.PayoutThreshold.ToString()) $($_.PayoutThresholdCurrency) payment threshold"
Write-Host "Estimated Payment Date: $(If ($_.EstimatedPayDate -is [DateTime]) { $_.EstimatedPayDate.ToString("G") } Else { $_.EstimatedPayDate })`n"
}
Remove-Variable Currency -ErrorAction Ignore
}
If ($Variables.MinersMissingBinary) {
Write-Host "`n"
Write-Host "Some miners binaries are missing, downloader is installing miner binaries..." -ForegroundColor Yellow
}
If ($Variables.Miners | Where-Object Available -EQ $true | Where-Object { $_.Benchmark -eq $true -or $_.MeasurePowerUsage -eq $true }) {
If ($Config.UIStyle -ne "Full") {
$Variables.UIStyle = "Full"
Write-Host "Benchmarking / Measuring power usage: Temporarily switched UI style to 'Full' (Information about miners run in the past, failed miners & watchdog timers will $(If ($Variables.UIStyle -eq "Light") { "not " } )be shown)" -ForegroundColor Yellow
}
}
# Display available miners list
[System.Collections.ArrayList]$Miner_Table = @(
@{ Label = "Miner"; Expression = { $_.Name } }
@{ Label = "Algorithm"; Expression = { $_.Workers.Pool.Algorithm -join " & "} }
If ($Config.ShowMinerFee -and ($Variables.Miners.Workers.Fee )) { @{ Label = "Fee"; Expression = { $_.Workers.Fee | ForEach-Object { "{0:P2}" -f [Double]$_ } } } }
@{ Label = "Hashrate"; Expression = { If (-not $_.Benchmark) { $_.Workers | ForEach-Object { "$($_.Speed | ConvertTo-Hash)/s" } } Else { If ($_.Status -eq "Running") { "Benchmarking..." } Else { "Benchmark pending" } } }; Align = "right" }
If ($Config.ShowEarning) { @{ Label = "Earning"; Expression = { If (-not [Double]::IsNaN($_.Earning)) { ConvertTo-LocalCurrency -Value $_.Earning -Rate $Variables.Rates.BTC.($Config.Currency) -Offset 1 } Else { "Unknown" } }; Align = "right" } }
If ($Config.ShowEarningBias) { @{ Label = "EarningBias"; Expression = { If (-not [Double]::IsNaN($_.Earning_Bias)) { ConvertTo-LocalCurrency -Value $_.Earning_Bias -Rate $Variables.Rates.BTC.($Config.Currency) -Offset 1 } Else { "Unknown" } }; Align = "right" } }
If ($Config.CalculatePowerCost -and $Config.ShowPowerUsage) { @{ Label = "PowerUsage"; Expression = { If (-not $_.MeasurePowerUsage) { "$($_.PowerUsage.ToString("N2")) W" } Else { If ($_.Status -eq "Running") { "Measuring..." } Else { "Unmeasured" } } }; Align = "right" } }
If ($Config.CalculatePowerCost -and $Config.ShowPowerCost -and $Variables.MiningPowerCost) { @{ Label = "PowerCost"; Expression = { If ($Variables.PowerPricekWh -eq 0) { (0).ToString("N$(Get-DigitsFromValue -Value $Variables.Rates.BTC.($Config.Currency) -Offset 1)") } Else { If (-not [Double]::IsNaN($_.PowerUsage)) { "-$(ConvertTo-LocalCurrency -Value ($_.PowerCost) -Rate ($Variables.Rates.($Config.PayoutCurrency).($Config.Currency)) -Offset 1)" } Else { "Unknown" } } }; Align = "right" } }
If ($Config.CalculatePowerCost -and $Config.ShowProfit -and $Variables.MiningPowerCost) { @{ Label = "Profit"; Expression = { If (-not [Double]::IsNaN($_.Profit)) { ConvertTo-LocalCurrency -Value $_.Profit -Rate $Variables.Rates.BTC.($Config.Currency) -Offset 1 } Else { "Unknown" } }; Align = "right" } }
If ($Config.CalculatePowerCost -and $Config.ShowProfitBias -and $Variables.MiningPowerCost) { @{ Label = "ProfitBias"; Expression = { If (-not [Double]::IsNaN($_.Profit_Bias)) { ConvertTo-LocalCurrency -Value $_.Profit_Bias -Rate $Variables.Rates.BTC.($Config.Currency) -Offset 1 } Else { "Unknown" } }; Align = "right" } }
If ($Config.ShowAccuracy) { @{ Label = "Accuracy"; Expression = { $_.Workers.Pool.MarginOfError | ForEach-Object { "{0:P0}" -f [Double](1 - $_) } }; Align = "right" } }
@{ Label = "Pool"; Expression = { $_.Workers.Pool.Name -join " & " } }
If ($Config.ShowPoolFee -and ($Variables.Miners.Workers.Pool.Fee )) { @{ Label = "Fee"; Expression = { $_.Workers.Pool.Fee | ForEach-Object { "{0:P2}" -f [Double]$_ } } } }
If ($Variables.Miners.Workers.Pool.Currency) { @{ Label = "Currency"; Expression = { $_.Workers.Pool.Currency } } }
If ($Variables.Miners.Workers.Pool.CoinName) { @{ Label = "CoinName"; Expression = { $_.Workers.Pool.CoinName } } }
)
If ($Variables.CalculatePowerCost) { $SortBy = "Profit" } Else { $SortBy = "Earning" }
$Variables.Miners | Where-Object Available -EQ $true | Group-Object -Property { $_.DeviceName } | Sort-Object Name | ForEach-Object {
$MinersDeviceGroup = @($_.Group)
$MinersDeviceGroupNeedingBenchmark = @($MinersDeviceGroup | Where-Object Benchmark -EQ $true)
$MinersDeviceGroupNeedingPowerUsageMeasurement = @($MinersDeviceGroup | Where-Object Enabled -EQ $True | Where-Object MeasurePowerUsage -EQ $true)
$MinersDeviceGroup = @($MinersDeviceGroup | Where-Object { $Variables.ShowAllMiners -or $_.Fastest -eq $true -or $MinersDeviceGroupNeedingBenchmark.Count -gt 0 -or $MinersDeviceGroupNeedingPowerUsageMeasurement.Count -gt 0 } )
$MinersDeviceGroup | Where-Object {
$Variables.ShowAllMiners -or <#List all miners#>
$_.$SortBy -ge ($MinersDeviceGroup.$SortBy | Sort-Object -Descending | Select-Object -Index (($MinersDeviceGroup.Count, 5 | Measure-Object -Minimum).Minimum - 1)) -or <#Always list at least the top 5 miners per device group#>
$_.$SortBy -ge (($MinersDeviceGroup.$SortBy | Sort-Object -Descending | Select-Object -Index 0) * 0.5) -or <#Always list the better 50% miners per device group#>
$MinersDeviceGroupNeedingBenchmark.Count -gt 0 -or <#List all miners when benchmarking#>
$MinersDeviceGroupNeedingPowerUsageMeasurement.Count -gt 0 <#List all miners when measuring power usage#>
} | Sort-Object -Property DeviceName, @{ Expression = { $_.Benchmark -eq $true }; Descending = $true }, @{ Expression = { $_.MeasurePowerUsage -eq $true }; Descending = $true }, @{ Expression = { $_."$($SortBy)_Bias" }; Descending = $true }, @{ Expression = { $_.Name }; Descending = $false }, @{ Expression = { $_.Algorithm[0] }; Descending = $false }, @{ Expression = { $_.Algorithm[1] }; Descending = $false } |
Format-Table $Miner_Table -GroupBy @{ Name = "Device$(If (@($_).Count -ne 1) { "s" })"; Expression = { "$($_.DeviceName -join ', ') [$(($Variables.Devices | Where-Object Name -In $_.DeviceName).Model -join ', ')]" } } | Out-Host
# Display benchmarking progress
If ($MinersDeviceGroupNeedingBenchmark) {
"Benchmarking for device$(If (($MinersDeviceGroup.DeviceName | Select-Object -Unique).Count -gt 1) { " group" } ) ($(($MinersDeviceGroup.DeviceName | Sort-Object -Unique ) -join '; ')) in progress: $($MinersDeviceGroupNeedingBenchmark.Count) miner$(If ($MinersDeviceGroupNeedingBenchmark.Count -gt 1){ 's' }) left to complete benchmark." | Out-Host
}
# Display power usage measurement progress
If ($MinersDeviceGroupNeedingPowerUsageMeasurement) {
"Power usage measurement for device$(If (($MinersDeviceGroup.DeviceName | Select-Object -Unique).Count -gt 1) { " group" } ) ($(($MinersDeviceGroup.DeviceName | Sort-Object -Unique ) -join '; ')) in progress: $($MinersDeviceGroupNeedingPowerUsageMeasurement.Count) miner$(If ($MinersDeviceGroupNeedingPowerUsageMeasurement.Count -gt 1) { 's' }) left to complete measuring." | Out-Host
}
}
If ($ProcessesRunning = @($Variables.Miners | Where-Object { $_.Status -eq "Running" })) {
Write-Host "Running miner$(If ($ProcessesRunning.Count -eq 1) { ":" } Else { "s: $($ProcessesRunning.Count)" })"
$ProcessesRunning | Sort-Object { If ($null -eq $_.Process) { [DateTime]0 } Else { $_.Process.StartTime } } | Format-Table -Wrap (
@{ Label = "Hashrate"; Expression = { If ($_.Speed_Live) { (($_.Speed_Live | ForEach-Object { "$($_ | ConvertTo-Hash)/s" }) -join ' & ' ) -replace '\s+', ' ' } Else { "n/a" } }; Align = "right" },
@{ Label = "PowerUsage"; Expression = { If ($_.PowerUsage_Live) { "$($_.PowerUsage_Live.ToString("N2")) W" } Else { "n/a" } }; Align = "right" },
@{ Label = "Active (this run)"; Expression = { "{0:dd} days {0:hh} hrs {0:mm} min {0:ss} sec" -f ((Get-Date).ToUniversalTime() - $_.BeginTime) } },
@{ Label = "Active (total)"; Expression = { "{0:dd} days {0:hh} hrs {0:mm} min {0:ss} sec" -f ($_.TotalMiningDuration) } },
@{ Label = "Cnt"; Expression = { Switch ($_.Activated) { 0 { "Never" } 1 { "Once" } Default { "$_" } } } },
@{ Label = "Command"; Expression = { "$($_.Path.TrimStart((Convert-Path ".\"))) $(Get-CommandLineParameters $_.Arguments)" } }
) | Out-Host
}
If ($Variables.UIStyle -eq "Full") {
If ($ProcessesIdle = @($Variables.Miners | Where-Object { $_.Activated -and $_.Status -eq "Idle" -and $_.GetActiveLast().ToLocalTime().AddHours(24) -gt (Get-Date) })) {
Write-Host "Previously executed miner$(If ($ProcessesIdle.Count -eq 1) { ":" } Else { "s: $($ProcessesIdle.Count)" }) in the past 24 hrs"
$ProcessesIdle | Sort-Object { $_.Process.StartTime } -Descending | Select-Object -First ($MinersDeviceGroup.Count * 3) | Format-Table -Wrap (
@{ Label = "Hashrate"; Expression = { (($_.Workers.Speed | ForEach-Object { If (-not [Double]::IsNaN($_)) { "$($_ | ConvertTo-Hash)/s" } Else { "n/a" } }) -join ' & ' ) -replace '\s+', ' ' }; Align = "right" },
@{ Label = "PowerUsage"; Expression = { If (-not [Double]::IsNaN($_.PowerUsage)) { "$($_.PowerUsage.ToString("N2")) W" } Else { "n/a" } }; Align = "right" },
@{ Label = "Time since last run"; Expression = { "{0:dd} days {0:hh} hrs {0:mm} min {0:ss} sec" -f $((Get-Date) - $_.GetActiveLast().ToLocalTime()) } },
@{ Label = "Active (total)"; Expression = { "{0:dd} days {0:hh} hrs {0:mm} min {0:ss} sec" -f $_.TotalMiningDuration } },
@{ Label = "Cnt"; Expression = { Switch ($_.Activated) { 0 { "Never" } 1 { "Once" } Default { "$_" } } } },
@{ Label = "Command"; Expression = { "$($_.Path.TrimStart((Convert-Path ".\"))) $(Get-CommandLineParameters $_.Arguments)" } }
) | Out-Host
}
If ($ProcessesFailed = @($Variables.Miners | Where-Object { $_.Activated -and $_.Status -eq "Failed" -and $_.GetActiveLast().ToLocalTime().AddHours(24) -gt (Get-Date)})) {
Write-Host -ForegroundColor Red "Failed miner$(If ($ProcessesFailed.Count -eq 1) { ":" } Else { "s: $($ProcessesFailed.Count)" }) in the past 24 hrs"
$ProcessesFailed | Sort-Object { If ($null -eq $_.Process) { [DateTime]0 } Else { $_.Process.StartTime } } | Format-Table -Wrap (
@{ Label = "Hashrate"; Expression = { (($_.Workers.Speed | ForEach-Object { If (-not [Double]::IsNaN($_)) { "$($_ | ConvertTo-Hash)/s" } Else { "n/a" } }) -join ' & ' ) -replace '\s+', ' ' }; Align = "right" },
@{ Label = "PowerUsage"; Expression = { If (-not [Double]::IsNaN($_.PowerUsage)) { "$($_.PowerUsage.ToString("N2")) W" } Else { "n/a" } }; Align = "right" },
@{ Label = "Time since last fail"; Expression = { "{0:dd} days {0:hh} hrs {0:mm} min {0:ss} sec" -f $((Get-Date) - $_.GetActiveLast().ToLocalTime()) } },
@{ Label = "Active (total)"; Expression = { "{0:dd} days {0:hh} hrs {0:mm} min {0:ss} sec" -f $_.TotalMiningDuration } },
@{ Label = "Cnt"; Expression = { Switch ($_.Activated) { 0 { "Never" } 1 { "Once" } Default { "$_" } } } },
@{ Label = "Command"; Expression = { "$($_.Path.TrimStart((Convert-Path ".\"))) $(Get-CommandLineParameters $_.Arguments)" } }
) | Out-Host
}
}
Remove-Variable SortBy
Remove-Variable MinersDeviceGroup -ErrorAction SilentlyContinue
Remove-Variable MinersDeviceGroupNeedingBenchmark -ErrorAction SilentlyContinue
Remove-Variable MinersDeviceGroupNeedingPowerUsageMeasurement -ErrorAction SilentlyContinue
Remove-Variable Miner_Table -ErrorAction SilentlyContinue
If ($Config.Watchdog -eq $true -and $Variables.UIStyle -eq "Full") {
# Display watchdog timers
$Variables.WatchdogTimers | Where-Object Kicked -GT $Variables.Timer.AddSeconds( -$Variables.WatchdogReset) | Format-Table -Wrap (
@{Label = "Miner Watchdog Timers"; Expression = { $_.MinerName } },
@{Label = "Pool"; Expression = { $_.PoolName } },
@{Label = "Algorithm"; Expression = { $_.Algorithm } },
@{Label = "Device(s)"; Expression = { $_.DeviceName } },
@{Label = "Last Updated"; Expression = { "{0:mm} min {0:ss} sec ago" -f ((Get-Date).ToUniversalTime() - $_.Kicked) }; Align = "right" }
) | Out-Host
}
$Variables.Summary -split '<br>' | ForEach-Object { Write-Host ($_ -replace ' ', ' ' -replace ' +', '; ' -replace '; $') }
If (-not $Variables.Paused) {
If ($Variables.Miners | Where-Object Available -EQ $true | Where-Object { $_.Benchmark -eq $false -or $_.MeasurePowerUsage -eq $false }) {
If ($Variables.MiningEarning -lt $Variables.MiningPowerCost) {
# Mining causes a loss
Write-Host -ForegroundColor Red "Mining is currently NOT profitable and causes a loss of $($Config.Currency) $((($Variables.MiningProfit - $Variables.BasePowerCostBTC) * $Variables.Rates.BTC.($Config.Currency)).ToString("N$(Get-DigitsFromValue -Value $Variables.Rates.($Config.PayoutCurrency).($Config.Currency) -Offset 1)"))/day (including Base Power Cost)."
}
If (($Variables.MiningEarning - $Variables.MiningPowerCost) -lt $Config.ProfitabilityThreshold) {
# Mining profit is below the configured threshold
Write-Host -ForegroundColor Blue "Mining profit ($($Config.Currency) $(ConvertTo-LocalCurrency -Value ($Variables.MiningProfit - $Variables.BasePowerCostBTC) -Rate $Variables.Rates.BTC.($Config.Currency) -Offset 1)) is below the configured threshold of $($Config.Currency) $($Config.ProfitabilityThreshold.ToString("N$((Get-Culture).NumberFormat.CurrencyDecimalDigits)"))/day; mining is suspended until threshold is reached."
}
}
}
Write-Host "--------------------------------------------------------------------------------"
Write-Host -ForegroundColor Yellow "Last refresh: $($Variables.Timer.ToLocalTime().ToString('G')) | Next refresh: $($Variables.EndLoopTime.ToString('G'))"
}
$Variables.RefreshNeeded = $false
}
$TimerUI.Start()
}
Function MainForm_Load {
$MainForm.Text = "$($Branding.ProductLabel) $($Variables.CurrentVersion)"
$LabelMiningStatus.Text = "$($Branding.ProductLabel) $($Variables.CurrentVersion)"
$MainForm.Number = 0
$TimerUI.Add_Tick(
{
# Display mining information
If ($host.UI.RawUI.KeyAvailable) {
$KeyPressed = $host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown, IncludeKeyUp"); Start-Sleep -Milliseconds 300; $host.UI.RawUI.FlushInputBuffer()
If ($KeyPressed.KeyDown) {
Switch ($KeyPressed.Character) {
"a" {
$Variables.ShowAllMiners = -not $Variables.ShowAllMiners
Write-Host "Toggled displaying all available miners to " -NoNewline; If ($Variables.ShowAllMiners) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "."
$Variables.RefreshNeeded = $true
Start-Sleep -Seconds 2
}
"b" {
$Variables.ShowPoolBalances = -not $Variables.ShowPoolBalances
Write-Host "Toggled displaying pool balances to " -NoNewline; If ($Variables.ShowPoolBalances) { Write-Host "on" -ForegroundColor Green -NoNewline } Else { Write-Host "off" -ForegroundColor Red -NoNewline }; Write-Host "."
$Variables.RefreshNeeded = $true
Start-Sleep -Seconds 2
}
"s" {
If ($Variables.UIStyle -eq "Light") { $Variables.UIStyle = "Full" }
Else { $Variables.UIStyle = "Light" }
Write-Host "UI style set to " -NoNewline; Write-Host "$($Variables.UIStyle)" -ForegroundColor Blue -NoNewline; Write-Host " (Information about miners run in the past, failed miners & watchdog timers will " -NoNewline; If ($Variables.UIStyle -eq "Light") { Write-Host "not" -ForegroundColor Red -NoNewline; Write-Host " " -NoNewline }; Write-Host "be shown)."
$Variables.RefreshNeeded = $true
Start-Sleep -Seconds 2
}
}
}
}
# Timer never disposes objects until it is disposed
$MainForm.Number += 1
$TimerUI.Stop()
TimerUITick
If ($MainForm.Number -gt 6000) {
$MainForm.Number = 0
$TimerUI.Remove_Tick( { TimerUITick } )
$TimerUI.Dispose()
$TimerUI = New-Object System.Windows.Forms.Timer
$TimerUI.Add_Tick( { TimerUITick } )
}
$TimerUI.Start()
}
)