Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 136 additions & 1 deletion BitPoolMiner/BitPoolMiner.csproj

Large diffs are not rendered by default.

267 changes: 262 additions & 5 deletions BitPoolMiner/Miners/CryptoDredge.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,281 @@
using System.IO;
using BitPoolMiner.Models;
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Threading.Tasks;
using System.Windows;
using System.IO;
using System.Text;
using System.Globalization;
using System.Linq;
using BitPoolMiner.Enums;
using BitPoolMiner.Utils;

namespace BitPoolMiner.Miners
{
/// <summary>
/// This class is for CryptoDredge which is ccminer fork derived class.
/// This class is for CryptoDredge derived class.
/// </summary>
public class CryptoDredge : Ccminer
public class CryptoDredge : Miner
{
public CryptoDredge(HardwareType hardwareType, MinerBaseType minerBaseType) : base(hardwareType, minerBaseType, false)
public CryptoDredge(HardwareType hardwareType, MinerBaseType minerBaseType) : base("Ccminer", hardwareType, minerBaseType, true)
{
string versionedDirectory = "";
MinerFileName = "CryptoDredge.exe";
versionedDirectory = "CryptoDredge_0.11.0_win_x64";

MinerWorkingDirectory = Path.Combine(Utils.Core.GetBaseMinersDir(), versionedDirectory);

ApiPort = 4068;
HostName = "127.0.0.1";
}

public override void Start()
{
MinerProcess = StartProcess();
}

public override void Stop()
{
try
{
StopProcess();
}
catch (Exception e)
{
throw new ApplicationException(string.Format("There was an error killing the miner process {0} with PID {1}", MinerProcess.MinerProcess.ProcessName, MinerProcess.MinerProcess.Handle), e);
}
}

#region Monitoring Statistics

public async override void ReportStatsAsyc()
{
try
{
var minerMonitorStat = await GetRPCResponse();

if (minerMonitorStat == null)
return;

System.Threading.Thread.Sleep(4000);
PostMinerMonitorStat(minerMonitorStat);
}
catch (Exception e)
{
NLogProcessing.LogError(e, "Error reporting stats for Ccminer");
}
}

private async Task<MinerMonitorStat> GetRPCResponse()
{
MinerMonitorStat minerMonitorStat = new MinerMonitorStat();
try
{
int gpuNumber = 0;
var dictHW = CryptoDredgeApi.GetHwInfo(HostName, ApiPort);
var dictHist = CryptoDredgeApi.GetHistory(HostName, ApiPort);
var dictSummary = CryptoDredgeApi.GetSummary(HostName, ApiPort);

minerMonitorStat.AccountGuid = (Guid)Application.Current.Properties["AccountID"];
minerMonitorStat.WorkerName = Application.Current.Properties["WorkerName"].ToString();
minerMonitorStat.CoinType = CoinType;
minerMonitorStat.MinerBaseType = MinerBaseType;

var gpuList = dictHW.ToList();

// Remove the last element in the list
gpuList.RemoveAt(gpuList.Count - 1);

List<GPUMonitorStat> gpuMonitorStatList = new List<GPUMonitorStat>();

foreach (var gpu in gpuList)
{
//var gpuHash = (from element in dictHist
// orderby element["GPU"] ascending, element["TS"] descending
// where element["GPU"] == gpuNumber
// select element).FirstOrDefault();

var gpuHw = (from hw in dictHW
where hw["GPU"].ToString() == gpuNumber.ToString()
select hw).FirstOrDefault();

// Create new GPU monitor stats object and map values
GPUMonitorStat gpuMonitorStat = new GPUMonitorStat();

gpuMonitorStat.AccountGuid = (Guid)Application.Current.Properties["AccountID"];
gpuMonitorStat.WorkerName = Application.Current.Properties["WorkerName"].ToString();
gpuMonitorStat.CoinType = CoinType;
gpuMonitorStat.GPUID = Convert.ToInt32(gpuNumber);
//gpuMonitorStat.HashRate = (Convert.ToDecimal(gpuHash["KHS"]));
gpuMonitorStat.FanSpeed = Convert.ToInt16(gpuHw["FAN"]);
gpuMonitorStat.Temp = (short)Convert.ToDecimal(gpuHw["TEMP"]);
gpuMonitorStat.Power = (short)(Convert.ToDecimal(gpuHw["POWER"]) / 1000);
gpuMonitorStat.HardwareType = Hardware;

// Sum up power and hashrate
minerMonitorStat.Power += (short)gpuMonitorStat.Power;
minerMonitorStat.HashRate += gpuMonitorStat.HashRate;

// Add GPU stats to list
gpuMonitorStatList.Add(gpuMonitorStat);
gpuNumber++;

}

// Set list of GPU monitor stats
minerMonitorStat.GPUMonitorStatList = gpuMonitorStatList;

return await Task.Run(() => { return minerMonitorStat; });

}
catch (Exception ex)
{
NLogProcessing.LogError(ex, "Error calling GetRPCResponse from miner.");

// Return null object;
return null;
}
}
}
}

internal static class CryptoDredgeApi
{
// Converts the results from Pruvots api to an array of dictionaries to get more JSON like results
public static Dictionary<string, string>[] ConvertPruvotToDictArray(string apiResult)
{
if (apiResult == null) return null;

// Will return a Dict per GPU
string[] splitGroups = apiResult.Split('|');

Dictionary<string, string>[] totalDict = new Dictionary<string, string>[splitGroups.Length - 1];

for (int index = 0; index < splitGroups.Length - 1; index++)
{
Dictionary<string, string> separateDict = new Dictionary<string, string>();
string[] keyValues = splitGroups[index].Split(';');
for (int i = 0; i < keyValues.Length; i++)
{
string[] elements = keyValues[i].Split('=');
if (elements.Length > 1) separateDict.Add(elements[0], elements[1]);
}
totalDict[index] = separateDict;
}

return totalDict;
}

public static T GetDictValue<T>(Dictionary<string, string> dictionary, string key)
{
string value;

if (dictionary.TryGetValue(key, out value))
{
return (T)Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture);
}

// Unsigneds can't be negative
if (typeof(T) == typeof(uint)) return (T)Convert.ChangeType(9001, typeof(T), CultureInfo.InvariantCulture);
return (T)Convert.ChangeType(-1, typeof(T), CultureInfo.InvariantCulture);
}

// Overload that just returns the string without type conversion
public static string GetDictValue(Dictionary<string, string> dictionary, string key)
{
string value;

if (dictionary.TryGetValue(key, out value))
{
return value;
}

return "-1";
}

public static Dictionary<string, string>[] GetSummary(string ip = "127.0.0.1", int port = 4068)
{
return Request(ip, port, "summary");
}

public static Dictionary<string, string>[] GetHwInfo(string ip = "127.0.0.1", int port = 4068)
{
return Request(ip, port, "hwinfo");
}

public static Dictionary<string, string>[] GetMemInfo(string ip = "127.0.0.1", int port = 4068)
{
return Request(ip, port, "meminfo");
}

public static Dictionary<string, string>[] GetThreads(string ip = "127.0.0.1", int port = 4068)
{
return Request(ip, port, "threads");
}

public static Dictionary<string, string>[] GetHistory(string ip = "127.0.0.1", int port = 4068, int minerMap = -1)
{
Dictionary<string, string>[] histo = Request(ip, port, "histo");

if (histo == null) return null;

bool existsInHisto = false;
foreach (Dictionary<string, string> log in histo)
{
if (GetDictValue<int>(log, "GPU") == minerMap)
{
existsInHisto = true;
break;
}
}

if (existsInHisto || minerMap == -1) return minerMap == -1 ? histo : Request(ip, port, "histo|" + minerMap);

return null;
}

public static Dictionary<string, string>[] GetPoolInfo(string ip = "127.0.0.1", int port = 4068)
{
return Request(ip, port, "pool");
}

public static Dictionary<string, string>[] GetScanLog(string ip = "127.0.0.1", int port = 4068)
{
return Request(ip, port, "scanlog");
}

public static Dictionary<string, string>[] Request(string ip, int port, string message)
{
string responseData = "";

try
{
using (TcpClient client = new TcpClient(ip, port))
{
using (NetworkStream stream = client.GetStream())
{
byte[] data = Encoding.ASCII.GetBytes(message);
stream.Write(data, 0, data.Length);
stream.Flush();

data = new Byte[4096];

int bytes = stream.Read(data, 0, data.Length);
responseData = Encoding.ASCII.GetString(data, 0, bytes);
}

}
}
catch (Exception e)
{
NLogProcessing.LogError(e, $"Error getting Request from ccminer on port {port}");
return null;
}


return ConvertPruvotToDictArray(responseData);
}
}

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<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">
<assemblyIdentity name="BitPoolMiner.application" version="1.0.1.14" publicKeyToken="4eb951c39ace8231" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
<description asmv2:publisher="BitPoolMining" co.v1:suiteName="BitPoolMining" asmv2:product="BitPoolMiner" xmlns="urn:schemas-microsoft-com:asm.v1" />
<deployment install="true" mapFileExtensions="true" co.v1:createDesktopShortcut="true">
<subscription>
<update>
<expiration maximumAge="0" unit="days" />
</update>
</subscription>
<deploymentProvider codebase="https://raw.githubusercontent.com/BitPoolMining/BitPoolMiner/master/BitPoolMiner/publish/BitPoolMiner.application" />
</deployment>
<compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2">
<framework targetVersion="4.6.1" profile="Full" supportedRuntime="4.0.30319" />
</compatibleFrameworks>
<dependency>
<dependentAssembly dependencyType="install" codebase="Application Files\BitPoolMiner_1_0_1_14\BitPoolMiner.exe.manifest" size="64361">
<assemblyIdentity name="BitPoolMiner.exe" version="1.0.1.14" publicKeyToken="4eb951c39ace8231" language="neutral" processorArchitecture="msil" type="win32" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>+/DOUAtD/jhJVUPFRsaMhCJx0alNpNwEPbCGmanqAUY=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
</configuration>
Binary file not shown.
Loading