forked from MultiPoolMiner/MultiPoolMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiPoolMiner.ps1
447 lines (395 loc) · 29.1 KB
/
MultiPoolMiner.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
param(
[Parameter(Mandatory = $false)]
[String]$Wallet,
[Parameter(Mandatory = $false)]
[String]$UserName,
[Parameter(Mandatory = $false)]
[String]$WorkerName = "multipoolminer",
[Parameter(Mandatory = $false)]
[Int]$API_ID = 0,
[Parameter(Mandatory = $false)]
[String]$API_Key = "",
[Parameter(Mandatory = $false)]
[Int]$Interval = 60, #seconds before reading hash rate from miners
[Parameter(Mandatory = $false)]
[String]$Region = "europe", #europe/us/asia
[Parameter(Mandatory = $false)]
[Switch]$SSL = $false,
[Parameter(Mandatory = $false)]
[Array]$Type = $null, #AMD/NVIDIA/CPU
[Parameter(Mandatory = $false)]
[Array]$Algorithm = $null, #i.e. Ethash,Equihash,CryptoNight ect.
[Parameter(Mandatory = $false)]
[Array]$MinerName = $null,
[Parameter(Mandatory = $false)]
[Array]$PoolName = $null,
[Parameter(Mandatory = $false)]
[Array]$Currency = ("BTC", "USD"), #i.e. GBP,EUR,ZEC,ETH ect.
[Parameter(Mandatory = $false)]
[Int]$Donate = 10, #Minutes per Day
[Parameter(Mandatory = $false)]
[String]$Proxy = "", #i.e http://192.0.0.1:8080
[Parameter(Mandatory = $false)]
[Int]$Delay = 0 #seconds before opening each miner
)
Set-Location (Split-Path $script:MyInvocation.MyCommand.Path)
if (Get-Command "Unblock-File" -ErrorAction SilentlyContinue) {Get-ChildItem . -Recurse | Unblock-File}
if (Get-Command "Get-MpPreference" -ErrorAction SilentlyContinue) {if ((Get-MpPreference).ExclusionPath -notcontains (Convert-Path .)) {Start-Process powershell -Verb runAs -ArgumentList "Add-MpPreference -ExclusionPath '$(Convert-Path .)'"}}
if ($Proxy -eq "") {$PSDefaultParameterValues.Remove("*:Proxy")}
else {$PSDefaultParameterValues["*:Proxy"] = $Proxy}
. .\Include.ps1
$StatEnd = (Get-Date).ToUniversalTime()
$DecayStart = (Get-Date).ToUniversalTime()
$DecayPeriod = 60 #seconds
$DecayBase = 1 - 0.1 #decimal percentage
$ActiveMiners = @()
#Start the log
Start-Transcript ".\Logs\$(Get-Date -Format "yyyy-MM-dd_HH-mm-ss").txt"
#Set donation parameters
$LastDonated = (Get-Date).ToUniversalTime().AddDays(-1).AddHours(1)
$WalletDonate = "1Q24z7gHPDbedkaWDTFqhMF8g7iHMehsCb"
$UserNameDonate = "aaronsace"
$WorkerNameDonate = "multipoolminer"
$WalletBackup = $Wallet
$UserNameBackup = $UserName
$WorkerNameBackup = $WorkerName
while ($true) {
$StatStart = $StatEnd
$StatEnd = (Get-Date).ToUniversalTime().AddSeconds($Interval)
$StatSpan = New-TimeSpan $StatStart $StatEnd
$DecayExponent = [int](((Get-Date).ToUniversalTime() - $DecayStart).TotalSeconds / $DecayPeriod)
#Activate or deactivate donation
if ((Get-Date).ToUniversalTime().AddDays(-1).AddMinutes($Donate) -ge $LastDonated) {
$Wallet = $WalletDonate
$UserName = $UserNameDonate
$WorkerName = $WorkerNameDonate
}
if ((Get-Date).ToUniversalTime().AddDays(-1) -ge $LastDonated) {
$Wallet = $WalletBackup
$UserName = $UserNameBackup
$WorkerName = $WorkerNameBackup
$LastDonated = (Get-Date).ToUniversalTime()
}
$Rates = [PSCustomObject]@{}
$Currency | ForEach-Object {$Rates | Add-Member $_ (Invoke-WebRequest "https://api.cryptonator.com/api/ticker/btc-$_" -UseBasicParsing | ConvertFrom-Json).ticker.price}
#Load the Stats
$Stats = [PSCustomObject]@{}
if (Test-Path "Stats") {Get-ChildItemContent "Stats" | ForEach-Object {$Stats | Add-Member $_.Name $_.Content}}
#Load information about the Pools
$AllPools = if (Test-Path "Pools") {
Get-ChildItemContent "Pools" | ForEach-Object {$_.Content | Add-Member @{Name = $_.Name} -PassThru} |
Where-Object {$Algorithm.Count -eq 0 -or (Compare-Object $Algorithm $_.Algorithm -IncludeEqual -ExcludeDifferent | Measure-Object).Count -gt 0}
}
if ($AllPools.Count -eq 0) {"No Pools!" | Out-Host; Start-Sleep $Interval; continue}
$Pools = [PSCustomObject]@{}
$Pools_Comparison = [PSCustomObject]@{}
$AllPools.Algorithm | ForEach-Object {$_.ToLower()} | Select-Object -Unique | ForEach-Object {$Pools | Add-Member $_ ($AllPools | Sort-Object -Descending {$PoolName.Count -eq 0 -or (Compare-Object $PoolName $_.Name -IncludeEqual -ExcludeDifferent | Measure-Object).Count -gt 0}, Price, {$_.Region -EQ $Region}, {$_.SSL -EQ $SSL} | Where-Object Algorithm -EQ $_ | Select-Object -First 1)}
$AllPools.Algorithm | ForEach-Object {$_.ToLower()} | Select-Object -Unique | ForEach-Object {$Pools_Comparison | Add-Member $_ ($AllPools | Sort-Object -Descending {$PoolName.Count -eq 0 -or (Compare-Object $PoolName $_.Name -IncludeEqual -ExcludeDifferent | Measure-Object).Count -gt 0}, StablePrice, {$_.Region -EQ $Region}, {$_.SSL -EQ $SSL} | Where-Object Algorithm -EQ $_ | Select-Object -First 1)}
#Load information about the Miners
#Messy...?
$AllMiners = if (Test-Path "Miners") {
Get-ChildItemContent "Miners" | ForEach-Object {$_.Content | Add-Member @{Name = $_.Name} -PassThru} |
Where-Object {$Type.Count -eq 0 -or (Compare-Object $Type $_.Type -IncludeEqual -ExcludeDifferent | Measure-Object).Count -gt 0} |
Where-Object {($Algorithm.Count -eq 0 -or (Compare-Object $Algorithm $_.HashRates.PSObject.Properties.Name | Where-Object SideIndicator -EQ "=>" | Measure-Object).Count -eq 0) -and ((Compare-Object $Pools.PSObject.Properties.Name $_.HashRates.PSObject.Properties.Name | Where-Object SideIndicator -EQ "=>" | Measure-Object).Count -eq 0)} |
Where-Object {$MinerName.Count -eq 0 -or (Compare-Object $MinerName $_.Name -IncludeEqual -ExcludeDifferent | Measure-Object).Count -gt 0}
}
$AllMiners | ForEach-Object {
$Miner = $_
$Miner_HashRates = [PSCustomObject]@{}
$Miner_Pools = [PSCustomObject]@{}
$Miner_Pools_Comparison = [PSCustomObject]@{}
$Miner_Profits = [PSCustomObject]@{}
$Miner_Profits_Comparison = [PSCustomObject]@{}
$Miner_Profits_MarginOfError = [PSCustomObject]@{}
$Miner_Profits_Bias = [PSCustomObject]@{}
$Miner_Types = $Miner.Type | Select-Object -Unique
$Miner_Indexes = $Miner.Index | Select-Object -Unique
$Miner_Devices = $Miner.Device | Select-Object -Unique
$Miner.HashRates.PSObject.Properties.Name | ForEach-Object { #temp fix, must use 'PSObject.Properties' to preserve order
$Miner_HashRates | Add-Member $_ ([Double]$Miner.HashRates.$_)
$Miner_Pools | Add-Member $_ ([PSCustomObject]$Pools.$_)
$Miner_Pools_Comparison | Add-Member $_ ([PSCustomObject]$Pools_Comparison.$_)
$Miner_Profits | Add-Member $_ ([Double]$Miner.HashRates.$_ * $Pools.$_.Price)
$Miner_Profits_Comparison | Add-Member $_ ([Double]$Miner.HashRates.$_ * $Pools_Comparison.$_.StablePrice)
$Miner_Profits_Bias | Add-Member $_ ([Double]$Miner.HashRates.$_ * $Pools.$_.Price * (1 - ($Pools.$_.MarginOfError * [Math]::Pow($DecayBase, $DecayExponent))))
}
$Miner_Profit = [Double]($Miner_Profits.PSObject.Properties.Value | Measure-Object -Sum).Sum
$Miner_Profit_Comparison = [Double]($Miner_Profits_Comparison.PSObject.Properties.Value | Measure-Object -Sum).Sum
$Miner_Profit_Bias = [Double]($Miner_Profits_Bias.PSObject.Properties.Value | Measure-Object -Sum).Sum
$Miner.HashRates | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name | ForEach-Object {
$Miner_Profits_MarginOfError | Add-Member $_ ([Double]$Pools.$_.MarginOfError * (& {if ($Miner_Profit) {([Double]$Miner.HashRates.$_ * $Pools_Comparison.$_.StablePrice) / $Miner_Profit}else {1}}))
}
$Miner_Profit_MarginOfError = [Double]($Miner_Profits_MarginOfError.PSObject.Properties.Value | Measure-Object -Sum).Sum
$Miner.HashRates | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name | ForEach-Object {
if (-not [String]$Miner.HashRates.$_) {
$Miner_HashRates.$_ = $null
$Miner_Profits.$_ = $null
$Miner_Profits_Comparison.$_ = $null
$Miner_Profits_Bias.$_ = $null
$Miner_Profit = $null
$Miner_Profit_Comparison = $null
$Miner_Profits_MarginOfError = $null
$Miner_Profit_Bias = $null
}
}
if ($Miner_Types -eq $null) {$Miner_Types = $AllMiners.Type | Select-Object -Unique}
if ($Miner_Indexes -eq $null) {$Miner_Indexes = $AllMiners.Index | Select-Object -Unique}
if ($Miner_Types -eq $null) {$Miner_Types = ""}
if ($Miner_Indexes -eq $null) {$Miner_Indexes = 0}
$Miner.HashRates = $Miner_HashRates
$Miner | Add-Member Pools $Miner_Pools
$Miner | Add-Member Profits $Miner_Profits
$Miner | Add-Member Profits_Comparison $Miner_Profits_Comparison
$Miner | Add-Member Profits_Bias $Miner_Profits_Bias
$Miner | Add-Member Profit $Miner_Profit
$Miner | Add-Member Profit_Comparison $Miner_Profit_Comparison
$Miner | Add-Member Profit_MarginOfError $Miner_Profit_MarginOfError
$Miner | Add-Member Profit_Bias $Miner_Profit_Bias
$Miner | Add-Member Type ($Miner_Types | Sort-Object) -Force
$Miner | Add-Member Index ($Miner_Indexes | Sort-Object) -Force
$Miner | Add-Member Device ($Miner_Devices | Sort-Object) -Force
$Miner | Add-Member Device_Auto (($Miner_Devices -eq $null) | Sort-Object) -Force
$Miner.Path = [System.IO.Path]::GetFullPath($Miner.Path)
}
$Miners = $AllMiners | Where-Object {Test-Path $_.Path}
if (-not (Get-Job -State Running)) {
Start-Job -InitializationScript ([scriptblock]::Create("Set-Location('$(Get-Location)')")) -ArgumentList ($AllMiners | Select-Object URI, Path, @{name = "Searchable"; expression = {$Miner = $_; ($AllMiners | Where-Object {(Split-Path $_.Path -Leaf) -eq (Split-Path $Miner.Path -Leaf) -and $_.URI -ne $Miner.URI}).Count -eq 0}} -Unique) -FilePath .\Downloader.ps1 | Out-Null
}
if (Get-Command "Get-NetFirewallRule" -ErrorAction SilentlyContinue) {
if ($MinerFirewalls -eq $null) {$MinerFirewalls = Get-NetFirewallRule | Where-Object DisplayName -EQ "MultiPoolMiner" | Get-NetFirewallApplicationFilter | Select-Object -ExpandProperty Program}
if (@($AllMiners | Select-Object -ExpandProperty Path -Unique) | Compare-Object @($MinerFirewalls) | Where-Object SideIndicator -EQ "=>") {
Start-Process powershell ("('$(@($AllMiners | Select-Object -ExpandProperty Path -Unique) | Compare-Object @($MinerFirewalls) | Where-Object SideIndicator -EQ '=>' | Select-Object -ExpandProperty InputObject | ConvertTo-Json -Compress)' | ConvertFrom-Json) | ForEach {New-NetFirewallRule -DisplayName 'MultiPoolMiner' -Program `$_}" -replace '"', '\"') -Verb runAs
$MinerFirewalls = $null
}
}
if ($Miners.Count -eq 0) {"No Miners!" | Out-Host; Start-Sleep $Interval; continue}
#Update the active miners
$ActiveMiners | ForEach-Object {
$_.Profit = 0
$_.Profit_Comparison = 0
$_.Profit_MarginOfError = 0
$_.Profit_Bias = 0
$_.Best = $false
$_.Best_Comparison = $false
}
$Miners | ForEach-Object {
$Miner = $_
$ActiveMiner = $ActiveMiners | Where-Object {
$_.Name -eq $Miner.Name -and
$_.Path -eq $Miner.Path -and
$_.Arguments -eq $Miner.Arguments -and
$_.Wrap -eq $Miner.Wrap -and
$_.API -eq $Miner.API -and
$_.Port -eq $Miner.Port -and
(Compare-Object $_.Algorithm ($Miner.HashRates | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name) | Measure-Object).Count -eq 0
}
if ($ActiveMiner) {
$ActiveMiner.Type = $Miner.Type
$ActiveMiner.Index = $Miner.Index
$ActiveMiner.Device = $Miner.Device
$ActiveMiner.Device_Auto = $Miner.Device_Auto
$ActiveMiner.Profit = $Miner.Profit
$ActiveMiner.Profit_Comparison = $Miner.Profit_Comparison
$ActiveMiner.Profit_MarginOfError = $Miner.Profit_MarginOfError
$ActiveMiner.Profit_Bias = $Miner.Profit_Bias
$ActiveMiner.Speed = $Miner.HashRates | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name | ForEach-Object {$Miner.HashRates.$_}
}
else {
$ActiveMiners += [PSCustomObject]@{
Name = $Miner.Name
Path = $Miner.Path
Arguments = $Miner.Arguments
Wrap = $Miner.Wrap
API = $Miner.API
Port = $Miner.Port
Algorithm = $Miner.HashRates.PSObject.Properties.Name #temp fix, must use 'PSObject.Properties' to preserve order
Type = $Miner.Type
Index = $Miner.Index
Device = $Miner.Device
Device_Auto = $Miner.Device_Auto
Profit = $Miner.Profit
Profit_Comparison = $Miner.Profit_Comparison
Profit_MarginOfError = $Miner.Profit_MarginOfError
Profit_Bias = $Miner.Profit_Bias
Speed = $Miner.HashRates | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name | ForEach-Object {$Miner.HashRates.$_}
Speed_Live = 0
Best = $false
Best_Comparison = $false
Process = $null
New = $false
Active = [TimeSpan]0
Activated = 0
Status = ""
HashRate = 0
Benchmarked = 0
}
}
}
$ActiveMiners | Where-Object Device_Auto | ForEach-Object {
$Miner = $_
$Miner.Device = ($Miners | Where-Object {(Compare-Object $Miner.Type $_.Type -IncludeEqual -ExcludeDifferent | Measure-Object).Count -gt 0}).Device | Select-Object -Unique | Sort-Object
if ($Miner.Device -eq $null) {$Miner.Device = ($Miners | Where-Object {(Compare-Object $Miner.Type $_.Type -IncludeEqual -ExcludeDifferent | Measure-Object).Count -gt 0}).Type | Select-Object -Unique | Sort-Object}
}
#Don't penalize active miners
$ActiveMiners | Where-Object Status -EQ "Running" | ForEach-Object {$_.Profit_Bias = $_.Profit}
#Get most profitable miner combination i.e. AMD+NVIDIA+CPU
$BestMiners = $ActiveMiners | Select-Object Type, Index -Unique | ForEach-Object {$Miner_GPU = $_; ($ActiveMiners | Where-Object {(Compare-Object $Miner_GPU.Type $_.Type | Measure-Object).Count -eq 0 -and (Compare-Object $Miner_GPU.Index $_.Index | Measure-Object).Count -eq 0} | Sort-Object -Descending {($_ | Where-Object Profit -EQ $null | Measure-Object).Count}, {($_ | Measure-Object Profit_Bias -Sum).Sum}, {($_ | Where-Object Profit -NE 0 | Measure-Object).Count} | Select-Object -First 1)}
$BestDeviceMiners = $ActiveMiners | Select-Object Device -Unique | ForEach-Object {$Miner_GPU = $_; ($ActiveMiners | Where-Object {(Compare-Object $Miner_GPU.Device $_.Device | Measure-Object).Count -eq 0} | Sort-Object -Descending {($_ | Where-Object Profit -EQ $null | Measure-Object).Count}, {($_ | Measure-Object Profit_Bias -Sum).Sum}, {($_ | Where-Object Profit -NE 0 | Measure-Object).Count} | Select-Object -First 1)}
$BestMiners_Comparison = $ActiveMiners | Select-Object Type, Index -Unique | ForEach-Object {$Miner_GPU = $_; ($ActiveMiners | Where-Object {(Compare-Object $Miner_GPU.Type $_.Type | Measure-Object).Count -eq 0 -and (Compare-Object $Miner_GPU.Index $_.Index | Measure-Object).Count -eq 0} | Sort-Object -Descending {($_ | Where-Object Profit -EQ $null | Measure-Object).Count}, {($_ | Measure-Object Profit_Comparison -Sum).Sum}, {($_ | Where-Object Profit -NE 0 | Measure-Object).Count} | Select-Object -First 1)}
$BestDeviceMiners_Comparison = $ActiveMiners | Select-Object Device -Unique | ForEach-Object {$Miner_GPU = $_; ($ActiveMiners | Where-Object {(Compare-Object $Miner_GPU.Device $_.Device | Measure-Object).Count -eq 0} | Sort-Object -Descending {($_ | Where-Object Profit -EQ $null | Measure-Object).Count}, {($_ | Measure-Object Profit_Comparison -Sum).Sum}, {($_ | Where-Object Profit -NE 0 | Measure-Object).Count} | Select-Object -First 1)}
$Miners_Type_Combos = @([PSCustomObject]@{Combination = @()}) + (Get-Combination ($ActiveMiners | Select-Object Type -Unique) | Where-Object {(Compare-Object ($_.Combination | Select-Object -ExpandProperty Type -Unique) ($_.Combination | Select-Object -ExpandProperty Type) | Measure-Object).Count -eq 0})
$Miners_Index_Combos = @([PSCustomObject]@{Combination = @()}) + (Get-Combination ($ActiveMiners | Select-Object Index -Unique) | Where-Object {(Compare-Object ($_.Combination | Select-Object -ExpandProperty Index -Unique) ($_.Combination | Select-Object -ExpandProperty Index) | Measure-Object).Count -eq 0})
$Miners_Device_Combos = (Get-Combination ($ActiveMiners | Select-Object Device -Unique) | Where-Object {(Compare-Object ($_.Combination | Select-Object -ExpandProperty Device -Unique) ($_.Combination | Select-Object -ExpandProperty Device) | Measure-Object).Count -eq 0})
$BestMiners_Combos = $Miners_Type_Combos | ForEach-Object {
$Miner_Type_Combo = $_.Combination
$Miners_Index_Combos | ForEach-Object {
$Miner_Index_Combo = $_.Combination
[PSCustomObject]@{
Combination = $Miner_Type_Combo | ForEach-Object {
$Miner_Type_Count = $_.Type.Count
[Regex]$Miner_Type_Regex = "^(" + (($_.Type | ForEach-Object {[Regex]::Escape($_)}) -join "|") + ")$"
$Miner_Index_Combo | ForEach-Object {
$Miner_Index_Count = $_.Index.Count
[Regex]$Miner_Index_Regex = "^(" + (($_.Index | ForEach-Object {[Regex]::Escape($_)}) -join "|") + ")$"
$BestMiners | Where-Object {([Array]$_.Type -notmatch $Miner_Type_Regex).Count -eq 0 -and ([Array]$_.Index -notmatch $Miner_Index_Regex).Count -eq 0 -and ([Array]$_.Type -match $Miner_Type_Regex).Count -eq $Miner_Type_Count -and ([Array]$_.Index -match $Miner_Index_Regex).Count -eq $Miner_Index_Count}
}
}
}
}
}
$BestMiners_Combos += $Miners_Device_Combos | ForEach-Object {
$Miner_Device_Combo = $_.Combination
[PSCustomObject]@{
Combination = $Miner_Device_Combo | ForEach-Object {
$Miner_Device_Count = $_.Device.Count
[Regex]$Miner_Device_Regex = "^(" + (($_.Device | ForEach-Object {[Regex]::Escape($_)}) -join "|") + ")$"
$BestDeviceMiners | Where-Object {([Array]$_.Device -notmatch $Miner_Device_Regex).Count -eq 0 -and ([Array]$_.Device -match $Miner_Device_Regex).Count -eq $Miner_Device_Count}
}
}
}
$BestMiners_Combos_Comparison = $Miners_Type_Combos | ForEach-Object {
$Miner_Type_Combo = $_.Combination
$Miners_Index_Combos | ForEach-Object {
$Miner_Index_Combo = $_.Combination
[PSCustomObject]@{
Combination = $Miner_Type_Combo | ForEach-Object {
$Miner_Type_Count = $_.Type.Count
[Regex]$Miner_Type_Regex = "^(" + (($_.Type | ForEach-Object {[Regex]::Escape($_)}) -join "|") + ")$"
$Miner_Index_Combo | ForEach-Object {
$Miner_Index_Count = $_.Index.Count
[Regex]$Miner_Index_Regex = "^(" + (($_.Index | ForEach-Object {[Regex]::Escape($_)}) -join "|") + ")$"
$BestMiners_Comparison | Where-Object {([Array]$_.Type -notmatch $Miner_Type_Regex).Count -eq 0 -and ([Array]$_.Index -notmatch $Miner_Index_Regex).Count -eq 0 -and ([Array]$_.Type -match $Miner_Type_Regex).Count -eq $Miner_Type_Count -and ([Array]$_.Index -match $Miner_Index_Regex).Count -eq $Miner_Index_Count}
}
}
}
}
}
$BestMiners_Combos_Comparison += $Miners_Device_Combos | ForEach-Object {
$Miner_Device_Combo = $_.Combination
[PSCustomObject]@{
Combination = $Miner_Device_Combo | ForEach-Object {
$Miner_Device_Count = $_.Device.Count
[Regex]$Miner_Device_Regex = "^(" + (($_.Device | ForEach-Object {[Regex]::Escape($_)}) -join "|") + ")$"
$BestDeviceMiners_Comparison | Where-Object {([Array]$_.Device -notmatch $Miner_Device_Regex).Count -eq 0 -and ([Array]$_.Device -match $Miner_Device_Regex).Count -eq $Miner_Device_Count}
}
}
}
$BestMiners_Combo = $BestMiners_Combos | Sort-Object -Descending {($_.Combination | Where-Object Profit -EQ $null | Measure-Object).Count}, {($_.Combination | Measure-Object Profit_Bias -Sum).Sum}, {($_.Combination | Where-Object Profit -NE 0 | Measure-Object).Count} | Select-Object -First 1 | Select-Object -ExpandProperty Combination
$BestMiners_Combo_Comparison = $BestMiners_Combos_Comparison | Sort-Object -Descending {($_.Combination | Where-Object Profit -EQ $null | Measure-Object).Count}, {($_.Combination | Measure-Object Profit_Comparison -Sum).Sum}, {($_.Combination | Where-Object Profit -NE 0 | Measure-Object).Count} | Select-Object -First 1 | Select-Object -ExpandProperty Combination
$BestMiners_Combo | ForEach-Object {$_.Best = $true}
$BestMiners_Combo_Comparison | ForEach-Object {$_.Best_Comparison = $true}
#Stop or start miners in the active list depending on if they are the most profitable
$ActiveMiners | Where-Object Activated -GT 0 | Where-Object Best -EQ $false | ForEach-Object {
if ($_.Process -eq $null) {
$_.Status = "Failed"
}
elseif ($_.Process.HasExited -eq $false) {
$_.Process.CloseMainWindow() | Out-Null
$_.Status = "Idle"
}
}
Start-Sleep $Delay #Wait to prevent BSOD
$ActiveMiners | Where-Object Best -EQ $true | ForEach-Object {
if ($_.Process -eq $null -or $_.Process.HasExited -ne $false) {
$DecayStart = (Get-Date).ToUniversalTime()
$_.New = $true
$_.Activated++
if ($_.Process -ne $null) {$_.Active += $_.Process.ExitTime - $_.Process.StartTime}
if ($_.Wrap) {$_.Process = Start-Process -FilePath "PowerShell" -ArgumentList "-executionpolicy bypass -command . '$(Convert-Path ".\Wrapper.ps1")' -ControllerProcessID $PID -Id '$($_.Port)' -FilePath '$($_.Path)' -ArgumentList '$($_.Arguments)' -WorkingDirectory '$(Split-Path $_.Path)'" -PassThru}
else {$_.Process = Start-SubProcess -FilePath $_.Path -ArgumentList $_.Arguments -WorkingDirectory (Split-Path $_.Path) -Priority ($_.Type | ForEach-Object {if ($_ -eq "CPU") {-2}else {-1}} | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum)}
if ($_.Process -eq $null) {$_.Status = "Failed"}
else {$_.Status = "Running"}
}
}
#Display mining information
Clear-Host
$Miners | Where-Object {$_.Profit -ge 1E-5 -or $_.Profit -eq $null} | Sort-Object -Descending Type, Profit | Format-Table -GroupBy Type (
@{Label = "Miner"; Expression = {$_.Name}},
@{Label = "Algorithm"; Expression = {$_.HashRates.PSObject.Properties.Name}},
@{Label = "Speed"; Expression = {$_.HashRates.PSObject.Properties.Value | ForEach-Object {if ($_ -ne $null) {"$($_ | ConvertTo-Hash)/s"}else {"Benchmarking"}}}; Align = 'right'},
@{Label = "BTC/Day"; Expression = {$_.Profits.PSObject.Properties.Value | ForEach-Object {if ($_ -ne $null) {$_.ToString("N5")}else {"Benchmarking"}}}; Align = 'right'},
@{Label = "BTC/GH/Day"; Expression = {$_.Pools.PSObject.Properties.Value.Price | ForEach-Object {($_ * 1000000000).ToString("N5")}}; Align = 'right'},
@{Label = "Pool"; Expression = {$_.Pools.PSObject.Properties.Value | ForEach-Object {if ($_.Info) {"$($_.Name)-$($_.Info)"}else {"$($_.Name)"}}}}
) | Out-Host
#Display active miners list
$ActiveMiners | Where-Object Activated -GT 0 | Sort-Object -Descending Status, {if ($_.Process -eq $null) {[DateTime]0}else {$_.Process.StartTime}} | Select-Object -First (1 + 6 + 6) | Format-Table -Wrap -GroupBy Status (
@{Label = "Speed"; Expression = {$_.Speed_Live | ForEach-Object {"$($_ | ConvertTo-Hash)/s"}}; Align = 'right'},
@{Label = "Active"; Expression = {"{0:dd} Days {0:hh} Hours {0:mm} Minutes" -f $(if ($_.Process -eq $null) {$_.Active}else {if ($_.Process.ExitTime -gt $_.Process.StartTime) {($_.Active + ($_.Process.ExitTime - $_.Process.StartTime))}else {($_.Active + ((Get-Date) - $_.Process.StartTime))}})}},
@{Label = "Launched"; Expression = {Switch ($_.Activated) {0 {"Never"} 1 {"Once"} Default {"$_ Times"}}}},
@{Label = "Command"; Expression = {"$($_.Path.TrimStart((Convert-Path ".\"))) $($_.Arguments)"}}
) | Out-Host
#Display profit comparison
if (($BestMiners_Combo | Where-Object Profit -EQ $null | Measure-Object).Count -eq 0) {
$MinerComparisons =
[PSCustomObject]@{"Miner" = "MultiPoolMiner"},
[PSCustomObject]@{"Miner" = $BestMiners_Combo_Comparison | ForEach-Object {"$($_.Name)-$($_.Algorithm -join "/")"}}
$BestMiners_Combo_Stat = Set-Stat -Name "Profit" -Value ($BestMiners_Combo | Measure-Object Profit -Sum).Sum -Duration $StatSpan
$MinerComparisons_Profit = $BestMiners_Combo_Stat.Week, ($BestMiners_Combo_Comparison | Measure-Object Profit_Comparison -Sum).Sum
$MinerComparisons_MarginOfError = $BestMiners_Combo_Stat.Week_Fluctuation, ($BestMiners_Combo_Comparison | ForEach-Object {$_.Profit_MarginOfError * (& {if ($MinerComparisons_Profit[1]) {$_.Profit_Comparison / $MinerComparisons_Profit[1]}else {1}})} | Measure-Object -Sum).Sum
$Currency | ForEach-Object {
$MinerComparisons[0] | Add-Member $_.ToUpper() ("{0:N5} $([Char]0x00B1){1:P0} ({2:N5}-{3:N5})" -f ($MinerComparisons_Profit[0] * $Rates.$_), $MinerComparisons_MarginOfError[0], (($MinerComparisons_Profit[0] * $Rates.$_) / (1 + $MinerComparisons_MarginOfError[0])), (($MinerComparisons_Profit[0] * $Rates.$_) * (1 + $MinerComparisons_MarginOfError[0])))
$MinerComparisons[1] | Add-Member $_.ToUpper() ("{0:N5} $([Char]0x00B1){1:P0} ({2:N5}-{3:N5})" -f ($MinerComparisons_Profit[1] * $Rates.$_), $MinerComparisons_MarginOfError[1], (($MinerComparisons_Profit[1] * $Rates.$_) / (1 + $MinerComparisons_MarginOfError[1])), (($MinerComparisons_Profit[1] * $Rates.$_) * (1 + $MinerComparisons_MarginOfError[1])))
}
if ($MinerComparisons_Profit[0] -gt $MinerComparisons_Profit[1]) {
$MinerComparisons_Range = ($MinerComparisons_MarginOfError | Measure-Object -Average | Select-Object -ExpandProperty Average), (($MinerComparisons_Profit[0] - $MinerComparisons_Profit[1]) / $MinerComparisons_Profit[1]) | Measure-Object -Minimum | Select-Object -ExpandProperty Minimum
Write-Host -BackgroundColor Yellow -ForegroundColor Black "MultiPoolMiner is between $([Math]::Round((((($MinerComparisons_Profit[0]-$MinerComparisons_Profit[1])/$MinerComparisons_Profit[1])-$MinerComparisons_Range)*100)))% and $([Math]::Round((((($MinerComparisons_Profit[0]-$MinerComparisons_Profit[1])/$MinerComparisons_Profit[1])+$MinerComparisons_Range)*100)))% more profitable than the fastest miner: "
}
$MinerComparisons | Out-Host
}
#Do nothing for a few seconds as to not overload the APIs and display miner download status
do {
Get-Job | Receive-Job
Start-Sleep 10
}while ((Get-Date).ToUniversalTime() -lt $StatEnd)
#Save current hash rates
$ActiveMiners | ForEach-Object {
$_.Speed_Live = 0
$Miner_HashRates = $null
if ($_.New) {$_.Benchmarked++}
if ($_.Process -eq $null -or $_.Process.HasExited) {
if ($_.Status -eq "Running") {$_.Status = "Failed"}
}
else {
$Miner_HashRates = Get-HashRate $_.API $_.Port ($_.New -and $_.Benchmarked -lt 3)
$_.Speed_Live = $Miner_HashRates | Select-Object -First $_.Algorithm.Count
$Miner_StatSpan = $StatSpan
if ($_.New) {$Miner_StatSpan = New-TimeSpan -Seconds ($StatSpan.TotalSeconds * 100)}
if ($Miner_HashRates.Count -ge $_.Algorithm.Count) {
for ($i = 0; $i -lt $_.Algorithm.Count; $i++) {
$Stat = Set-Stat -Name "$($_.Name)_$($_.Algorithm | Select-Object -Index $i)_HashRate" -Value ($Miner_HashRates | Select-Object -Index $i) -Duration $Miner_StatSpan
}
$_.New = $false
}
}
#Benchmark timeout
if ($_.Benchmarked -ge 6 -or ($_.Benchmarked -ge 2 -and $_.Activated -ge 2)) {
for ($i = $Miner_HashRates.Count; $i -lt $_.Algorithm.Count; $i++) {
if ((Get-Stat "$($_.Name)_$($_.Algorithm | Select-Object -Index $i)_HashRate") -eq $null) {
$Stat = Set-Stat -Name "$($_.Name)_$($_.Algorithm | Select-Object -Index $i)_HashRate" -Value 0 -Duration $StatSpan
}
}
}
}
}
#Stop the log
Stop-Transcript