@@ -36,7 +36,13 @@ public void Run(MasterConfigurationModel configuration)
36
36
continue ;
37
37
}
38
38
39
- var configArgument = GetConfigurationArgument ( configuration . PathsConfiguration . ConfigTemplate , outputPools ) ;
39
+ var currency = GetPoolCurrency ( outputPools ) ;
40
+ if ( string . IsNullOrWhiteSpace ( currency ) )
41
+ {
42
+ Console . WriteLine ( @"Instance {0}.{1} does not contain valid currency. Make sure currency for all pools is set to the same value." , RunConfigurationModel . ActiveSolutionConfiguration , i ) ;
43
+ continue ;
44
+ }
45
+
40
46
var utilizedHardware = instances . Hardware . Select ( x => new UtilizedHardware
41
47
{
42
48
Hardware = configuration . Hardware . GetValue ( x ) ,
@@ -47,7 +53,10 @@ public void Run(MasterConfigurationModel configuration)
47
53
var amdArgument = GetAmdArgument ( configuration . PathsConfiguration . AmdTemplate , configuration . AmdProfiles , utilizedHardware . Where ( x => x . Hardware . Type == "amd" ) . ToList ( ) ) ;
48
54
var nvidiaArgument = GetNvidiaArgument ( configuration . PathsConfiguration . NvidiaTemplate , configuration . NvidiaProfiles , utilizedHardware . Where ( x => x . Hardware . Type == "nvidia" ) . ToList ( ) ) ;
49
55
50
- RunMiner ( $ "{ configArgument } { cpuArgument } { amdArgument } { nvidiaArgument } ") ;
56
+ var configArgument = GetConfigurationArgument ( configuration . PathsConfiguration . ConfigTemplate ) ;
57
+ var poolsArgument = GetPoolsArgument ( configuration . PathsConfiguration . PoolsTemplate , outputPools , currency ) ;
58
+
59
+ RunMiner ( $ "{ configArgument } { poolsArgument } { cpuArgument } { amdArgument } { nvidiaArgument } ") ;
51
60
}
52
61
}
53
62
@@ -64,11 +73,19 @@ private static List<PrioritizedPoolEntry> GetOutputPools(IDictionary<string, Poo
64
73
TlsFingerprint = x . TlsFingerprint ,
65
74
WalletAddress = x . WalletAddress ,
66
75
UseNiceHash = x . UseNiceHash ,
67
- UseTls = x . UseTls
76
+ UseTls = x . UseTls ,
77
+ RigId = x . RigId ,
78
+ Currency = x . Currency
68
79
} )
69
80
. ToList ( ) ;
70
81
}
71
82
83
+ private static string GetPoolCurrency ( IEnumerable < PrioritizedPoolEntry > pools )
84
+ {
85
+ var currencies = pools . Select ( x => ( x . Currency ?? string . Empty ) . ToLower ( ) ) . Distinct ( ) . ToList ( ) ;
86
+ return currencies . Count != 1 ? null : currencies . First ( ) ;
87
+ }
88
+
72
89
private static void RunMiner ( string arguments )
73
90
{
74
91
var startInfo = new ProcessStartInfo ( Path . GetFullPath ( "xmr-stak.exe" ) , arguments )
@@ -81,14 +98,29 @@ private static void RunMiner(string arguments)
81
98
Process . Start ( startInfo ) ;
82
99
}
83
100
84
- private string GetConfigurationArgument ( string configurationTemplatePath , IReadOnlyCollection < PrioritizedPoolEntry > pools )
101
+ private string GetConfigurationArgument ( string configurationTemplatePath )
85
102
{
86
- var configPath = CreateTemporaryConfiguration ( configurationTemplatePath , "config" , "%POOLS%" , pools ) ;
103
+ var configPath = CreateTemporaryConfiguration ( configurationTemplatePath , "config" ) ;
87
104
ScheduleFileDelete ( configPath ) ;
88
105
89
106
return $ "--config \" { configPath } \" ";
90
107
}
91
108
109
+ private string GetPoolsArgument ( string poolsTemplatePath , IReadOnlyCollection < PrioritizedPoolEntry > pools , string currency )
110
+ {
111
+ foreach ( var prioritizedPoolEntry in pools )
112
+ {
113
+ prioritizedPoolEntry . Currency = null ;
114
+ }
115
+
116
+ var configPath = CreateTemporaryConfiguration ( poolsTemplatePath , "pools" ,
117
+ new VariableReplacement ( "%POOLS%" , pools ) ,
118
+ new VariableReplacement ( "%CURRENCY%" , currency ) ) ;
119
+ ScheduleFileDelete ( configPath ) ;
120
+
121
+ return $ "--poolconf \" { configPath } \" ";
122
+ }
123
+
92
124
private string GetCpuArgument ( string cpuTemplatePath , IDictionary < string , IList < CpuThreadEntry > > cpuConfiguration , ICollection < UtilizedHardware > entry )
93
125
{
94
126
if ( entry . Count == 0 )
@@ -97,7 +129,7 @@ private string GetCpuArgument(string cpuTemplatePath, IDictionary<string, IList<
97
129
}
98
130
99
131
var cpuProfile = entry . SelectMany ( x => cpuConfiguration . GetValue ( x . Profile ) ) . ToList ( ) ;
100
- var path = CreateTemporaryConfiguration ( cpuTemplatePath , "cpu" , "%THREADS%" , cpuProfile ) ;
132
+ var path = CreateTemporaryConfiguration ( cpuTemplatePath , "cpu" , new VariableReplacement ( "%THREADS%" , cpuProfile ) ) ;
101
133
ScheduleFileDelete ( path ) ;
102
134
103
135
return $ "--cpu \" { path } \" ";
@@ -124,7 +156,7 @@ private string GetAmdArgument(string amdTemplatePath, IDictionary<string, IList<
124
156
} ) )
125
157
. ToList ( ) ;
126
158
127
- var path = CreateTemporaryConfiguration ( amdTemplatePath , "amd" , "%THREADS%" , amdProfile ) ;
159
+ var path = CreateTemporaryConfiguration ( amdTemplatePath , "amd" , new VariableReplacement ( "%THREADS%" , amdProfile ) ) ;
128
160
ScheduleFileDelete ( path ) ;
129
161
130
162
return $ "--amd \" { path } \" ";
@@ -153,21 +185,40 @@ private string GetNvidiaArgument(string nvidiaTemplatePath, IDictionary<string,
153
185
} ) )
154
186
. ToList ( ) ;
155
187
156
- var path = CreateTemporaryConfiguration ( nvidiaTemplatePath , "nvidia" , "%THREADS%" , nvidiaProfile ) ;
188
+ var path = CreateTemporaryConfiguration ( nvidiaTemplatePath , "nvidia" , new VariableReplacement ( "%THREADS%" , nvidiaProfile ) ) ;
157
189
ScheduleFileDelete ( path ) ;
158
190
159
191
return $ "--nvidia \" { path } \" ";
160
192
}
161
193
162
- private static string CreateTemporaryConfiguration ( string templatePath , string type , string variable , object value )
194
+ private static string CreateTemporaryConfiguration ( string templatePath , string type , params VariableReplacement [ ] variables )
163
195
{
164
- var configTemplateContent = File . ReadAllText ( templatePath ) ;
165
- var configContent = configTemplateContent . Replace ( variable , JsonConvert . SerializeObject ( value , Formatting . Indented ) ) ;
196
+ var content = File . ReadAllText ( templatePath ) ;
197
+ if ( variables != null )
198
+ {
199
+ foreach ( var variable in variables )
200
+ {
201
+ content = content . Replace ( variable . Variable , JsonConvert . SerializeObject ( variable . Value , Formatting . Indented ) ) ;
202
+ }
203
+ }
204
+
166
205
var configPath = $ "{ Guid . NewGuid ( ) } .{ type } .txt";
167
- File . WriteAllText ( configPath , configContent ) ;
206
+ File . WriteAllText ( configPath , content ) ;
168
207
return configPath ;
169
208
}
170
209
210
+ private class VariableReplacement
211
+ {
212
+ public string Variable { get ; set ; }
213
+ public object Value { get ; set ; }
214
+
215
+ public VariableReplacement ( string variable , object value )
216
+ {
217
+ Variable = variable ;
218
+ Value = value ;
219
+ }
220
+ }
221
+
171
222
private void ScheduleFileDelete ( string file )
172
223
{
173
224
Finalizer . ScheduleFinalization ( ( ) =>
0 commit comments