forked from RainbowMiner/RainbowMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlazePool.ps1
123 lines (108 loc) · 5.63 KB
/
BlazePool.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
using module ..\Include.psm1
param(
[PSCustomObject]$Wallets,
[PSCustomObject]$Params,
[alias("WorkerName")]
[String]$Worker,
[TimeSpan]$StatSpan,
[String]$DataWindow = "estimate_current",
[Bool]$InfoOnly = $false,
[Bool]$AllowZero = $false,
[String]$StatAverage = "Minute_10"
)
$Name = Get-Item $MyInvocation.MyCommand.Path | Select-Object -ExpandProperty BaseName
$Pool_Request = [PSCustomObject]@{}
$PoolCoins_Request = [PSCustomObject]@{}
try {
$Pool_Request = Invoke-RestMethodAsync "http://api.blazepool.com/status" -retry 3 -retrywait 500 -tag $Name -cycletime 120
}
catch {
if ($Error.Count){$Error.RemoveAt(0)}
Write-Log -Level Warn "Pool API ($Name) has failed. "
return
}
if (($Pool_Request | Get-Member -MemberType NoteProperty -ErrorAction Ignore | Measure-Object Name).Count -le 1) {
Write-Log -Level Warn "Pool API ($Name) returned nothing. "
return
}
try {
$PoolCoins_Request = Invoke-RestMethodAsync "http://api.blazepool.com/currencies" -tag $Name -cycletime 120
}
catch {
if ($Error.Count){$Error.RemoveAt(0)}
Write-Log -Level Warn "Pool currencies API ($Name) has failed. "
}
[hashtable]$Pool_Algorithms = @{}
[hashtable]$Pool_Coins = @{}
[hashtable]$Pool_RegionsTable = @{}
$Pool_Regions = @("us")
$Pool_Regions | Foreach-Object {$Pool_RegionsTable.$_ = Get-Region $_}
$Pool_Currencies = @("BTC") | Select-Object -Unique | Where-Object {$Wallets.$_ -or $InfoOnly}
if ($PoolCoins_Request) {
$PoolCoins_Algorithms = @($Pool_Request.PSObject.Properties.Value | Where-Object coins -eq 1 | Select-Object -ExpandProperty name -Unique)
if ($PoolCoins_Algorithms.Count) {foreach($p in $PoolCoins_Request.PSObject.Properties.Name) {if ($PoolCoins_Algorithms -contains $PoolCoins_Request.$p.algo) {$Pool_Coins[$PoolCoins_Request.$p.algo] = [hashtable]@{Name = $PoolCoins_Request.$p.name; Symbol = $p -replace '-.+$'}}}}
}
$Pool_Request | Get-Member -MemberType NoteProperty -ErrorAction Ignore | Select-Object -ExpandProperty Name | Where-Object {([Double]$Pool_Request.$_.estimate_current -gt 0) -or $InfoOnly} | ForEach-Object {
$Pool_Host = "$_.mine.blazepool.com"
$Pool_Port = $Pool_Request.$_.port
$Pool_Algorithm = $Pool_Request.$_.name
if (-not $Pool_Algorithms.ContainsKey($Pool_Algorithm)) {$Pool_Algorithms[$Pool_Algorithm] = Get-Algorithm $Pool_Algorithm}
$Pool_Algorithm_Norm = $Pool_Algorithms[$Pool_Algorithm]
$Pool_Coin = $Pool_Coins.$Pool_Algorithm.Name
$Pool_Symbol = $Pool_Coins.$Pool_Algorithm.Symbol
$Pool_PoolFee = [Double]$Pool_Request.$_.fees
if ($Pool_Coin -and -not $Pool_Symbol) {$Pool_Symbol = Get-CoinSymbol $Pool_Coin}
$Pool_Factor = [Double]$Pool_Request.$_.mbtc_mh_factor
if ($Pool_Factor -le 0) {
Write-Log -Level Info "$($Name): Unable to determine divisor for algorithm $Pool_Algorithm. "
return
}
$Pool_TSL = ($PoolCoins_Request.PSObject.Properties.Value | Where-Object algo -eq $Pool_Algorithm | Measure-Object timesincelast -Minimum).Minimum
$Pool_BLK = ($PoolCoins_Request.PSObject.Properties.Value | Where-Object algo -eq $Pool_Algorithm | Measure-Object "24h_blocks" -Maximum).Maximum
if (-not $InfoOnly) {
$NewStat = $false; if (-not (Test-Path "Stats\Pools\$($Name)_$($Pool_Algorithm_Norm)_Profit.txt")) {$NewStat = $true; $DataWindow = "actual_last24h"}
$Pool_Price = Get-YiiMPValue $Pool_Request.$_ -DataWindow $DataWindow -Factor $Pool_Factor
$Stat = Set-Stat -Name "$($Name)_$($Pool_Algorithm_Norm)_Profit" -Value $Pool_Price -Duration $(if ($NewStat) {New-TimeSpan -Days 1} else {$StatSpan}) -ChangeDetection $(-not $NewStat) -Actual24h $($Pool_Request.$_.actual_last24h/1000) -Estimate24h $($Pool_Request.$_.estimate_last24h) -HashRate $Pool_Request.$_.hashrate -BlockRate $Pool_BLK -Quiet
if (-not $Stat.HashRate_Live -and -not $AllowZero) {return}
}
foreach($Pool_Region in $Pool_Regions) {
foreach($Pool_Currency in $Pool_Currencies) {
$Pool_Params = if ($Params.$Pool_Currency) {",$($Params.$Pool_Currency)"}
[PSCustomObject]@{
Algorithm = $Pool_Algorithm_Norm
Algorithm0 = $Pool_Algorithm_Norm
CoinName = $Pool_Coin
CoinSymbol = $Pool_Symbol
Currency = $Pool_Currency
Price = $Stat.$StatAverage #instead of .Live
StablePrice = $Stat.Week
MarginOfError = $Stat.Week_Fluctuation
Protocol = "stratum+tcp"
Host = $Pool_Host
Port = $Pool_Port
User = $Wallets.$Pool_Currency
Pass = "ID={workername:$Worker},c=$Pool_Currency{diff:,d=`$difficulty}$Pool_Params"
Region = $Pool_RegionsTable.$Pool_Region
SSL = $false
Updated = $Stat.Updated
PoolFee = $Pool_PoolFee
DataWindow = $DataWindow
Workers = $Pool_Request.$_.workers
Hashrate = $Stat.HashRate_Live
BLK = $Stat.BlockRate_Average
TSL = $Pool_TSL
ErrorRatio = $Stat.ErrorRatio
Name = $Name
Penalty = 0
PenaltyFactor = 1
Disabled = $false
HasMinerExclusions = $false
Price_Bias = 0.0
Price_Unbias = 0.0
Wallet = $Wallets.$Pool_Currency
Worker = "{workername:$Worker}"
Email = $Email
}
}
}
}