Skip to content

Commit 0898519

Browse files
committed
Added ability to set extra miner arguments
1 parent c8b0b31 commit 0898519

File tree

142 files changed

+5762
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+5762
-13
lines changed

BitPoolMiner/BitPoolMiner.csproj

Lines changed: 137 additions & 1 deletion
Large diffs are not rendered by default.

BitPoolMiner/Miners/Miner.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.ObjectModel;
77
using System.Linq;
8+
using System.Windows;
89

910
// This is the Miner base class.
1011

@@ -62,19 +63,33 @@ protected virtual BPMProcess StartProcess()
6263
var process = new BPMProcess();
6364

6465
IsMining = true;
66+
FormatPerMinerCoinCombo();
6567

66-
// DS - Hotfix for SUQA/TREX algo type
67-
// TODO - Fix this shit
68+
ObservableCollection<AccountMinerTypeExtraParams> AccountMinerTypeExtraParamsList = (ObservableCollection<AccountMinerTypeExtraParams>)Application.Current.Properties["AccountMinerTypeExtraParamsList"];
69+
AccountMinerTypeExtraParams accountMinerTypeExtraParams = AccountMinerTypeExtraParamsList.First(x => x.MinerBaseType == MinerBaseType);
6870

69-
if (MinerBaseType == MinerBaseType.TRex && CoinType == CoinType.SUQA)
71+
if (accountMinerTypeExtraParams != null && accountMinerTypeExtraParams.ExtraParams != String.Empty)
7072
{
71-
MinerArguments = MinerArguments.Replace("x16r", "x22i");
73+
// Add Extra Params
74+
MinerArguments = String.Format("{0} {1}", MinerArguments, accountMinerTypeExtraParams.ExtraParams);
7275
}
7376

7477
process.Start(MinerWorkingDirectory, MinerArguments, MinerFileName, Hardware == HardwareType.AMD, MinerBaseType);
7578
process.MinerProcess.Exited += MinerExited;
7679
return process;
7780
}
81+
/// <summary>
82+
/// Handle special scenarios
83+
/// </summary>
84+
private void FormatPerMinerCoinCombo()
85+
{
86+
// DS - Hotfix for SUQA/TREX algo type
87+
// TODO - Fix this shit
88+
if (MinerBaseType == MinerBaseType.TRex && CoinType == CoinType.SUQA)
89+
{
90+
MinerArguments = MinerArguments.Replace("x16r", "x22i");
91+
}
92+
}
7893

7994
/// <summary>
8095
/// Stops the miner process
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using BitPoolMiner.Enums;
2+
using Newtonsoft.Json;
3+
4+
namespace BitPoolMiner.Models
5+
{
6+
public class AccountMinerTypeExtraParams
7+
{
8+
/// <summary>
9+
/// Miner Type to Add Extra Param to
10+
/// </summary>
11+
public string MinerBaseTypeString { get; set; }
12+
13+
/// <summary>
14+
/// Miner Type to Add Extra Param to
15+
/// </summary>
16+
[JsonIgnore]
17+
public MinerBaseType MinerBaseType
18+
{
19+
get
20+
{
21+
MinerBaseType minerBaseType;
22+
if(System.Enum.TryParse(MinerBaseTypeString, out minerBaseType))
23+
{
24+
return minerBaseType;
25+
}
26+
else
27+
{
28+
return MinerBaseType.UNDEFINED;
29+
}
30+
}
31+
32+
}
33+
34+
/// <summary>
35+
/// Extra miner parameters to use
36+
/// </summary>
37+
public string ExtraParams { get; set; }
38+
}
39+
}

BitPoolMiner/Persistence/FileSystem/Base/FileConstants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ public static class FileNameConstants
4444
/// Config file used to store the worker settings
4545
/// </summary>
4646
public const string WorkerSettingsFileName = "WorkerSettings.json";
47+
48+
/// <summary>
49+
/// Config file used to store the miner extra params
50+
/// </summary>
51+
public const string MinerTypeExtraParamsFileName = "MinerTypeExtraParams.json";
4752
}
4853
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using BitPoolMiner.Models;
2+
using BitPoolMiner.Persistence.FileSystem.Base;
3+
using Newtonsoft.Json;
4+
using System;
5+
using System.IO;
6+
using BitPoolMiner.Utils;
7+
using BitPoolMiner.Enums;
8+
using System.Collections.Generic;
9+
using System.Collections.ObjectModel;
10+
11+
namespace BitPoolMiner.Persistence.FileSystem
12+
{
13+
/// <summary>
14+
/// Handles configuration file used to store the extra parameters for miner apps to use
15+
/// </summary>
16+
public class MinerTypeExtraParamsFile
17+
{
18+
/// <summary>
19+
/// Serialize object to JSON and write/overwrite file
20+
/// </summary>
21+
/// <param name="accountMinerTypeExtraParamsList"></param>
22+
public void WriteJsonToFile(ObservableCollection<AccountMinerTypeExtraParams> accountMinerTypeExtraParamsList)
23+
{
24+
string filePath = Path.Combine(FileConstants.ConfigFilePath(), FileNameConstants.MinerTypeExtraParamsFileName);
25+
26+
try
27+
{
28+
// serialize JSON directly to a file
29+
using (StreamWriter file = File.CreateText(filePath))
30+
{
31+
JsonSerializer serializer = new JsonSerializer();
32+
serializer.Serialize(file, accountMinerTypeExtraParamsList);
33+
}
34+
}
35+
catch (Exception e)
36+
{
37+
throw new ApplicationException(string.Format("Error writing file {0}", filePath), e);
38+
}
39+
}
40+
41+
/// <summary>
42+
/// Read object from file and deserialize JSON and map to object
43+
/// </summary>
44+
/// <returns></returns>
45+
public ObservableCollection<AccountMinerTypeExtraParams> ReadJsonFromFile()
46+
{
47+
string filePath = Path.Combine(FileConstants.ConfigFilePath(), FileNameConstants.MinerTypeExtraParamsFileName);
48+
49+
// Create new empty list of miner type extra params
50+
ObservableCollection<AccountMinerTypeExtraParams> accountMinerTypeExtraParamsList = new ObservableCollection<AccountMinerTypeExtraParams>();
51+
52+
try
53+
{
54+
if (File.Exists(filePath))
55+
{
56+
// deserialize JSON directly from a file
57+
using (StreamReader file = File.OpenText(filePath))
58+
{
59+
JsonSerializer serializer = new JsonSerializer();
60+
accountMinerTypeExtraParamsList = (ObservableCollection<AccountMinerTypeExtraParams>)serializer.Deserialize(file, typeof(ObservableCollection<AccountMinerTypeExtraParams>));
61+
}
62+
}
63+
else
64+
{
65+
accountMinerTypeExtraParamsList = InitEmptyMinerTypeExtraParams();
66+
}
67+
return accountMinerTypeExtraParamsList;
68+
}
69+
catch (Exception e)
70+
{
71+
accountMinerTypeExtraParamsList = InitEmptyMinerTypeExtraParams();
72+
73+
NLogProcessing.LogError(e, "Miner type extra parameters could not be loaded. Using default values.");
74+
75+
// Return defaults
76+
return accountMinerTypeExtraParamsList;
77+
}
78+
}
79+
80+
/// <summary>
81+
/// Initializes a new AccountMinerTypeExtraParams object (only called when one doesn't exist or cannot be read).
82+
/// </summary>
83+
/// <param name="accountMinerTypeExtraParams"></param>
84+
/// <returns></returns>
85+
private ObservableCollection<AccountMinerTypeExtraParams> InitEmptyMinerTypeExtraParams()
86+
{
87+
// Create new empty list of miner type extra params
88+
ObservableCollection<AccountMinerTypeExtraParams> accountMinerTypeExtraParamsList = new ObservableCollection<AccountMinerTypeExtraParams>();
89+
90+
// Set default values
91+
foreach (MinerBaseType minerBaseType in Enum.GetValues(typeof(MinerBaseType)))
92+
{
93+
// Don't add settings for Undefined
94+
if (minerBaseType != MinerBaseType.UNDEFINED)
95+
{
96+
AccountMinerTypeExtraParams accountMinerTypeExtraParams = new AccountMinerTypeExtraParams();
97+
accountMinerTypeExtraParams.MinerBaseTypeString = minerBaseType.ToString();
98+
accountMinerTypeExtraParams.ExtraParams = "";
99+
accountMinerTypeExtraParamsList.Add(accountMinerTypeExtraParams);
100+
}
101+
}
102+
// Write defaults to disk
103+
WriteJsonToFile(accountMinerTypeExtraParamsList);
104+
105+
return accountMinerTypeExtraParamsList;
106+
}
107+
}
108+
}

BitPoolMiner/ViewModels/AccountViewModel.cs

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ public ObservableCollection<GPUSettings> GPUSettingsList
107107
// WalletViewModel reference
108108
public WalletViewModel WalletViewModel { get; set; }
109109

110+
// Account Miner Type Extra Params property to bind to UI
111+
private ObservableCollection<AccountMinerTypeExtraParams> accountMinerTypeExtraParamsList;
112+
public ObservableCollection<AccountMinerTypeExtraParams> AccountMinerTypeExtraParamsList
113+
{
114+
get
115+
{
116+
return accountMinerTypeExtraParamsList;
117+
}
118+
set
119+
{
120+
accountMinerTypeExtraParamsList = value;
121+
OnPropertyChanged();
122+
}
123+
}
110124

111125
#endregion
112126

@@ -120,6 +134,7 @@ public ObservableCollection<GPUSettings> GPUSettingsList
120134
public RelayCommand CommandScanHardware { get; set; }
121135
public RelayCommand CommandSaveAccountWorkerHardware { get; set; }
122136
public RelayCommand CommandUpdateCoinType { get; set; }
137+
public RelayCommand CommandSaveAccountMinerTypeExtraParams { get; set; }
123138

124139
#endregion
125140

@@ -146,6 +161,7 @@ public AccountViewModel(MainWindowViewModel mainWindowViewModel)
146161
CommandScanHardware = new RelayCommand(ScanHardware);
147162
CommandSaveAccountWorkerHardware = new RelayCommand(PersistWorkerHardware);
148163
CommandUpdateCoinType = new RelayCommand(UpdateCoinType);
164+
CommandSaveAccountMinerTypeExtraParams = new RelayCommand(PersistMinerTypeExtraParams);
149165

150166
// Load previous GUID or get a new GUID
151167
InitAccountID();
@@ -159,10 +175,11 @@ public AccountViewModel(MainWindowViewModel mainWindowViewModel)
159175
// Load hardware settings from API or scan for hardware
160176
InitWorkerHardware();
161177

178+
// Load miner type extra params
179+
InitMinerTypeExtraParams();
180+
162181
// Update worker list on main window
163182
_mainWindowViewModel.GetAccountWorkerList();
164-
165-
166183
}
167184

168185
/// <summary>
@@ -268,7 +285,23 @@ private void InitWorkerHardware()
268285
// Set global variable for Worker Name
269286
Application.Current.Properties["GPUSettingsList"] = GPUSettingsList;
270287
}
271-
288+
289+
private void InitMinerTypeExtraParams()
290+
{
291+
try
292+
{
293+
// Attempt to read the miner type extra params from the config file
294+
MinerTypeExtraParamsFile minerTypeExtraParamsFile = new MinerTypeExtraParamsFile();
295+
AccountMinerTypeExtraParamsList = minerTypeExtraParamsFile.ReadJsonFromFile();
296+
297+
// Save list for later
298+
Application.Current.Properties["AccountMinerTypeExtraParamsList"] = AccountMinerTypeExtraParamsList;
299+
}
300+
catch (Exception e)
301+
{
302+
throw new ApplicationException(string.Format("Error getting miner type extra settings", e));
303+
}
304+
}
272305

273306
#endregion
274307

@@ -510,6 +543,54 @@ public void PersistWorkerSettings(object param)
510543

511544
#endregion
512545

546+
#region MinerTypeExtraParams
547+
548+
private bool ValidateMinerTypeExtraParams(ObservableCollection<AccountMinerTypeExtraParams> minerTypeExtraParamsValidateList)
549+
{
550+
bool isValid = true;
551+
552+
foreach (AccountMinerTypeExtraParams minerTypeExtraParams in minerTypeExtraParamsValidateList)
553+
{
554+
// Validate that miner type is set
555+
if (minerTypeExtraParams.MinerBaseType == MinerBaseType.UNDEFINED)
556+
{
557+
ShowError("Please select a miner type");
558+
isValid = false;
559+
}
560+
}
561+
562+
return isValid;
563+
}
564+
565+
public void PersistMinerTypeExtraParams(object param)
566+
{
567+
try
568+
{
569+
if (ValidateMinerTypeExtraParams(AccountMinerTypeExtraParamsList) == false)
570+
{
571+
return;
572+
}
573+
574+
// Write GUID to account identity config file
575+
MinerTypeExtraParamsFile minerTypeExtraParamsFile = new MinerTypeExtraParamsFile();
576+
minerTypeExtraParamsFile.WriteJsonToFile(AccountMinerTypeExtraParamsList);
577+
578+
// Notify UI of change
579+
OnPropertyChanged("AccountMinerTypeExtraParamsList");
580+
581+
Application.Current.Properties["AccountMinerTypeExtraParamsList"] = AccountMinerTypeExtraParamsList;
582+
583+
// Notify success
584+
ShowSuccess(string.Format("Miner type extra params saved"));
585+
}
586+
catch (Exception e)
587+
{
588+
throw new ApplicationException(string.Format("Error saving miner type extra params"), e);
589+
}
590+
}
591+
592+
#endregion
593+
513594
#region WorkerHardware
514595

515596
/// <summary>

0 commit comments

Comments
 (0)