Skip to content

Commit 6fdea1f

Browse files
authored
Merge pull request #46 from BitPoolMining/Dev
Fix for CryptoDredge API
2 parents e47e849 + e97012f commit 6fdea1f

File tree

138 files changed

+5676
-11
lines changed

Some content is hidden

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

138 files changed

+5676
-11
lines changed

BitPoolMiner/BitPoolMiner.csproj

Lines changed: 136 additions & 1 deletion
Large diffs are not rendered by default.
Lines changed: 262 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,281 @@
1-
using System.IO;
1+
using BitPoolMiner.Models;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Net.Sockets;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.IO;
8+
using System.Text;
9+
using System.Globalization;
10+
using System.Linq;
211
using BitPoolMiner.Enums;
12+
using BitPoolMiner.Utils;
313

414
namespace BitPoolMiner.Miners
515
{
616
/// <summary>
7-
/// This class is for CryptoDredge which is ccminer fork derived class.
17+
/// This class is for CryptoDredge derived class.
818
/// </summary>
9-
public class CryptoDredge : Ccminer
19+
public class CryptoDredge : Miner
1020
{
11-
public CryptoDredge(HardwareType hardwareType, MinerBaseType minerBaseType) : base(hardwareType, minerBaseType, false)
21+
public CryptoDredge(HardwareType hardwareType, MinerBaseType minerBaseType) : base("Ccminer", hardwareType, minerBaseType, true)
1222
{
1323
string versionedDirectory = "";
1424
MinerFileName = "CryptoDredge.exe";
1525
versionedDirectory = "CryptoDredge_0.11.0_win_x64";
26+
1627
MinerWorkingDirectory = Path.Combine(Utils.Core.GetBaseMinersDir(), versionedDirectory);
1728

1829
ApiPort = 4068;
1930
HostName = "127.0.0.1";
2031
}
2132

33+
public override void Start()
34+
{
35+
MinerProcess = StartProcess();
36+
}
37+
38+
public override void Stop()
39+
{
40+
try
41+
{
42+
StopProcess();
43+
}
44+
catch (Exception e)
45+
{
46+
throw new ApplicationException(string.Format("There was an error killing the miner process {0} with PID {1}", MinerProcess.MinerProcess.ProcessName, MinerProcess.MinerProcess.Handle), e);
47+
}
48+
}
49+
50+
#region Monitoring Statistics
51+
52+
public async override void ReportStatsAsyc()
53+
{
54+
try
55+
{
56+
var minerMonitorStat = await GetRPCResponse();
57+
58+
if (minerMonitorStat == null)
59+
return;
60+
61+
System.Threading.Thread.Sleep(4000);
62+
PostMinerMonitorStat(minerMonitorStat);
63+
}
64+
catch (Exception e)
65+
{
66+
NLogProcessing.LogError(e, "Error reporting stats for Ccminer");
67+
}
68+
}
69+
70+
private async Task<MinerMonitorStat> GetRPCResponse()
71+
{
72+
MinerMonitorStat minerMonitorStat = new MinerMonitorStat();
73+
try
74+
{
75+
int gpuNumber = 0;
76+
var dictHW = CryptoDredgeApi.GetHwInfo(HostName, ApiPort);
77+
var dictHist = CryptoDredgeApi.GetHistory(HostName, ApiPort);
78+
var dictSummary = CryptoDredgeApi.GetSummary(HostName, ApiPort);
79+
80+
minerMonitorStat.AccountGuid = (Guid)Application.Current.Properties["AccountID"];
81+
minerMonitorStat.WorkerName = Application.Current.Properties["WorkerName"].ToString();
82+
minerMonitorStat.CoinType = CoinType;
83+
minerMonitorStat.MinerBaseType = MinerBaseType;
84+
85+
var gpuList = dictHW.ToList();
86+
87+
// Remove the last element in the list
88+
gpuList.RemoveAt(gpuList.Count - 1);
89+
90+
List<GPUMonitorStat> gpuMonitorStatList = new List<GPUMonitorStat>();
91+
92+
foreach (var gpu in gpuList)
93+
{
94+
//var gpuHash = (from element in dictHist
95+
// orderby element["GPU"] ascending, element["TS"] descending
96+
// where element["GPU"] == gpuNumber
97+
// select element).FirstOrDefault();
98+
99+
var gpuHw = (from hw in dictHW
100+
where hw["GPU"].ToString() == gpuNumber.ToString()
101+
select hw).FirstOrDefault();
102+
103+
// Create new GPU monitor stats object and map values
104+
GPUMonitorStat gpuMonitorStat = new GPUMonitorStat();
105+
106+
gpuMonitorStat.AccountGuid = (Guid)Application.Current.Properties["AccountID"];
107+
gpuMonitorStat.WorkerName = Application.Current.Properties["WorkerName"].ToString();
108+
gpuMonitorStat.CoinType = CoinType;
109+
gpuMonitorStat.GPUID = Convert.ToInt32(gpuNumber);
110+
//gpuMonitorStat.HashRate = (Convert.ToDecimal(gpuHash["KHS"]));
111+
gpuMonitorStat.FanSpeed = Convert.ToInt16(gpuHw["FAN"]);
112+
gpuMonitorStat.Temp = (short)Convert.ToDecimal(gpuHw["TEMP"]);
113+
gpuMonitorStat.Power = (short)(Convert.ToDecimal(gpuHw["POWER"]) / 1000);
114+
gpuMonitorStat.HardwareType = Hardware;
115+
116+
// Sum up power and hashrate
117+
minerMonitorStat.Power += (short)gpuMonitorStat.Power;
118+
minerMonitorStat.HashRate += gpuMonitorStat.HashRate;
119+
120+
// Add GPU stats to list
121+
gpuMonitorStatList.Add(gpuMonitorStat);
122+
gpuNumber++;
123+
124+
}
125+
126+
// Set list of GPU monitor stats
127+
minerMonitorStat.GPUMonitorStatList = gpuMonitorStatList;
128+
129+
return await Task.Run(() => { return minerMonitorStat; });
130+
131+
}
132+
catch (Exception ex)
133+
{
134+
NLogProcessing.LogError(ex, "Error calling GetRPCResponse from miner.");
135+
136+
// Return null object;
137+
return null;
138+
}
139+
}
22140
}
23-
}
24141

142+
internal static class CryptoDredgeApi
143+
{
144+
// Converts the results from Pruvots api to an array of dictionaries to get more JSON like results
145+
public static Dictionary<string, string>[] ConvertPruvotToDictArray(string apiResult)
146+
{
147+
if (apiResult == null) return null;
148+
149+
// Will return a Dict per GPU
150+
string[] splitGroups = apiResult.Split('|');
151+
152+
Dictionary<string, string>[] totalDict = new Dictionary<string, string>[splitGroups.Length - 1];
153+
154+
for (int index = 0; index < splitGroups.Length - 1; index++)
155+
{
156+
Dictionary<string, string> separateDict = new Dictionary<string, string>();
157+
string[] keyValues = splitGroups[index].Split(';');
158+
for (int i = 0; i < keyValues.Length; i++)
159+
{
160+
string[] elements = keyValues[i].Split('=');
161+
if (elements.Length > 1) separateDict.Add(elements[0], elements[1]);
162+
}
163+
totalDict[index] = separateDict;
164+
}
165+
166+
return totalDict;
167+
}
168+
169+
public static T GetDictValue<T>(Dictionary<string, string> dictionary, string key)
170+
{
171+
string value;
172+
173+
if (dictionary.TryGetValue(key, out value))
174+
{
175+
return (T)Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture);
176+
}
177+
178+
// Unsigneds can't be negative
179+
if (typeof(T) == typeof(uint)) return (T)Convert.ChangeType(9001, typeof(T), CultureInfo.InvariantCulture);
180+
return (T)Convert.ChangeType(-1, typeof(T), CultureInfo.InvariantCulture);
181+
}
182+
183+
// Overload that just returns the string without type conversion
184+
public static string GetDictValue(Dictionary<string, string> dictionary, string key)
185+
{
186+
string value;
187+
188+
if (dictionary.TryGetValue(key, out value))
189+
{
190+
return value;
191+
}
192+
193+
return "-1";
194+
}
195+
196+
public static Dictionary<string, string>[] GetSummary(string ip = "127.0.0.1", int port = 4068)
197+
{
198+
return Request(ip, port, "summary");
199+
}
200+
201+
public static Dictionary<string, string>[] GetHwInfo(string ip = "127.0.0.1", int port = 4068)
202+
{
203+
return Request(ip, port, "hwinfo");
204+
}
205+
206+
public static Dictionary<string, string>[] GetMemInfo(string ip = "127.0.0.1", int port = 4068)
207+
{
208+
return Request(ip, port, "meminfo");
209+
}
210+
211+
public static Dictionary<string, string>[] GetThreads(string ip = "127.0.0.1", int port = 4068)
212+
{
213+
return Request(ip, port, "threads");
214+
}
215+
216+
public static Dictionary<string, string>[] GetHistory(string ip = "127.0.0.1", int port = 4068, int minerMap = -1)
217+
{
218+
Dictionary<string, string>[] histo = Request(ip, port, "histo");
219+
220+
if (histo == null) return null;
221+
222+
bool existsInHisto = false;
223+
foreach (Dictionary<string, string> log in histo)
224+
{
225+
if (GetDictValue<int>(log, "GPU") == minerMap)
226+
{
227+
existsInHisto = true;
228+
break;
229+
}
230+
}
231+
232+
if (existsInHisto || minerMap == -1) return minerMap == -1 ? histo : Request(ip, port, "histo|" + minerMap);
233+
234+
return null;
235+
}
236+
237+
public static Dictionary<string, string>[] GetPoolInfo(string ip = "127.0.0.1", int port = 4068)
238+
{
239+
return Request(ip, port, "pool");
240+
}
241+
242+
public static Dictionary<string, string>[] GetScanLog(string ip = "127.0.0.1", int port = 4068)
243+
{
244+
return Request(ip, port, "scanlog");
245+
}
246+
247+
public static Dictionary<string, string>[] Request(string ip, int port, string message)
248+
{
249+
string responseData = "";
250+
251+
try
252+
{
253+
using (TcpClient client = new TcpClient(ip, port))
254+
{
255+
using (NetworkStream stream = client.GetStream())
256+
{
257+
byte[] data = Encoding.ASCII.GetBytes(message);
258+
stream.Write(data, 0, data.Length);
259+
stream.Flush();
260+
261+
data = new Byte[4096];
262+
263+
int bytes = stream.Read(data, 0, data.Length);
264+
responseData = Encoding.ASCII.GetString(data, 0, bytes);
265+
}
266+
267+
}
268+
}
269+
catch (Exception e)
270+
{
271+
NLogProcessing.LogError(e, $"Error getting Request from ccminer on port {port}");
272+
return null;
273+
}
274+
275+
276+
return ConvertPruvotToDictArray(responseData);
277+
}
278+
}
279+
280+
#endregion
281+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
3+
<assemblyIdentity name="BitPoolMiner.application" version="1.0.1.14" publicKeyToken="4eb951c39ace8231" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
4+
<description asmv2:publisher="BitPoolMining" co.v1:suiteName="BitPoolMining" asmv2:product="BitPoolMiner" xmlns="urn:schemas-microsoft-com:asm.v1" />
5+
<deployment install="true" mapFileExtensions="true" co.v1:createDesktopShortcut="true">
6+
<subscription>
7+
<update>
8+
<expiration maximumAge="0" unit="days" />
9+
</update>
10+
</subscription>
11+
<deploymentProvider codebase="https://raw.githubusercontent.com/BitPoolMining/BitPoolMiner/master/BitPoolMiner/publish/BitPoolMiner.application" />
12+
</deployment>
13+
<compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2">
14+
<framework targetVersion="4.6.1" profile="Full" supportedRuntime="4.0.30319" />
15+
</compatibleFrameworks>
16+
<dependency>
17+
<dependentAssembly dependencyType="install" codebase="Application Files\BitPoolMiner_1_0_1_14\BitPoolMiner.exe.manifest" size="64361">
18+
<assemblyIdentity name="BitPoolMiner.exe" version="1.0.1.14" publicKeyToken="4eb951c39ace8231" language="neutral" processorArchitecture="msil" type="win32" />
19+
<hash>
20+
<dsig:Transforms>
21+
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
22+
</dsig:Transforms>
23+
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
24+
<dsig:DigestValue>+/DOUAtD/jhJVUPFRsaMhCJx0alNpNwEPbCGmanqAUY=</dsig:DigestValue>
25+
</hash>
26+
</dependentAssembly>
27+
</dependency>
28+
<publisherIdentity name="CN=DSTURT-SURFACE\dstur" issuerKeyHash="e52c1a52fe2c96e0cea6ee90dfad5b3aa9285afb" /><Signature Id="StrongNameSignature" xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha256" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /><Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /><DigestValue>p+LPYMwwWX/2cXw1W0Yf9znJC+f51KD6MSddzHoRgEQ=</DigestValue></Reference></SignedInfo><SignatureValue>Rm7uJGIjZNHLQ2XySbldLEtwiwW4Hbgg1WCjtONWYhoHy6EzqMALuCP114cp4mtkPTi/lYhdBkfKisfjUQUfJVz/43b1g0MbKWCQucmajr8r60zxuVwRszCKv7S5JnNUVohWWul+Vfc6dnS0DmOzghGFAjPcU75T74jVqtaUuHw=</SignatureValue><KeyInfo Id="StrongNameKeyInfo"><KeyValue><RSAKeyValue><Modulus>0N2j1jELxr2whZRV1BDtcUDcOARPClY+n8mSKqddyC4INatOTDnSL0lDCDAm1vI1LGLwogYDoKtIVAOtRtFzUPmLsJ2vHFwjOsb1TgXQuvZFJNmchbI9QaO3M4+efATGygi4DWpgtWSwmyarNHPSx2Od+W0Xx/HKCAJfjkijZaU=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue><msrel:RelData xmlns:msrel="http://schemas.microsoft.com/windows/rel/2005/reldata"><r:license xmlns:r="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:as="http://schemas.microsoft.com/windows/pki/2005/Authenticode"><r:grant><as:ManifestInformation Hash="4480117acc5d2731faa0d4f9e70bc939f71f465b357c71f67f5930cc60cfe2a7" Description="" Url=""><as:assemblyIdentity name="BitPoolMiner.application" version="1.0.1.14" publicKeyToken="4eb951c39ace8231" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" /></as:ManifestInformation><as:SignedBy /><as:AuthenticodePublisher><as:X509SubjectName>CN=DSTURT-SURFACE\dstur</as:X509SubjectName></as:AuthenticodePublisher></r:grant><r:issuer><Signature Id="AuthenticodeSignature" xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha256" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /><Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" /><DigestValue>PwqBpcBIC7OPo09GZ1Vun4yLSekY6Uff9T0O/N+hbkc=</DigestValue></Reference></SignedInfo><SignatureValue>u7/JX+a39N/tTN9ds+9FzWogeJtcOs/gukDzyET4sODInDSbHAPcpx8+TEzphES+/MbJr8oHywAUufA8sAkT7gS/kDGbdQhamS8pVRHIkMGE62wSN5H8UTQkTljR+ZhieFexLLDFnGoWw6RYOiuXnQqmJfrtMAyn9zZCZwyxUlU=</SignatureValue><KeyInfo><KeyValue><RSAKeyValue><Modulus>0N2j1jELxr2whZRV1BDtcUDcOARPClY+n8mSKqddyC4INatOTDnSL0lDCDAm1vI1LGLwogYDoKtIVAOtRtFzUPmLsJ2vHFwjOsb1TgXQuvZFJNmchbI9QaO3M4+efATGygi4DWpgtWSwmyarNHPSx2Od+W0Xx/HKCAJfjkijZaU=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue></KeyValue><X509Data><X509Certificate>MIIB6TCCAVKgAwIBAgIQMSF8bfMsQJFJBvCnjsSRajANBgkqhkiG9w0BAQsFADAzMTEwLwYDVQQDHigARABTAFQAVQBSAFQALQBTAFUAUgBGAEEAQwBFAFwAZABzAHQAdQByMB4XDTE4MDYxNDE5NDgyNloXDTE5MDYxNTAxNDgyNlowMzExMC8GA1UEAx4oAEQAUwBUAFUAUgBUAC0AUwBVAFIARgBBAEMARQBcAGQAcwB0AHUAcjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA0N2j1jELxr2whZRV1BDtcUDcOARPClY+n8mSKqddyC4INatOTDnSL0lDCDAm1vI1LGLwogYDoKtIVAOtRtFzUPmLsJ2vHFwjOsb1TgXQuvZFJNmchbI9QaO3M4+efATGygi4DWpgtWSwmyarNHPSx2Od+W0Xx/HKCAJfjkijZaUCAwEAATANBgkqhkiG9w0BAQsFAAOBgQAvVlpdo9XcpudUkYsVFltjDgxy7/PChctSOu63rXfeVIkXEt29ScfaWJxZM9iqREHxD3IafS910dObtPYIejHfqJvWazWey7SnnrJ1byJHMlb3AUan0xeZNMXl7rTn7LFmb76tcSiW4RO1bq2ii4e40sbkW4gjOiebmYIFs0pGrw==</X509Certificate></X509Data></KeyInfo></Signature></r:issuer></r:license></msrel:RelData></KeyInfo></Signature></asmv1:assembly>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
5+
</startup>
6+
</configuration>
367 KB
Binary file not shown.

0 commit comments

Comments
 (0)