From b9aa683881ee0d614914d468dc2fedb78998f9f4 Mon Sep 17 00:00:00 2001 From: nicehashdev Date: Thu, 22 Oct 2015 15:22:15 +0200 Subject: [PATCH] Fixes and improvements - Added more config options - Added $/Day income calculation - Bug fixes --- NiceHashMiner/Bitcoin.cs | 61 ++++++++++++++++++++ NiceHashMiner/Config.cs | 1 + NiceHashMiner/Form1.Designer.cs | 71 +++++++++++++++++++++--- NiceHashMiner/Form1.cs | 51 +++++++++++++---- NiceHashMiner/Miner.cs | 2 +- NiceHashMiner/NiceHashMiner.csproj | 1 + NiceHashMiner/Properties/AssemblyInfo.cs | 4 +- NiceHashMiner/cpuminer.cs | 36 +++++++++--- README.md | 1 + 9 files changed, 196 insertions(+), 32 deletions(-) create mode 100644 NiceHashMiner/Bitcoin.cs diff --git a/NiceHashMiner/Bitcoin.cs b/NiceHashMiner/Bitcoin.cs new file mode 100644 index 0000000..c8e5e46 --- /dev/null +++ b/NiceHashMiner/Bitcoin.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Net; +using System.IO; +using Newtonsoft.Json; + +namespace NiceHashMiner +{ + class Bitcoin + { +#pragma warning disable 649 + class CoinbaseResponse + { + public double amount; + public string currency; + } +#pragma warning restore 649 + + public static double GetUSDExchangeRate() + { + string jsondata = GetCoinbaseAPIData("https://api.coinbase.com/v1/prices/spot_rate"); + if (jsondata == null) return 0; + + try + { + CoinbaseResponse cbr = JsonConvert.DeserializeObject(jsondata); + return cbr.amount; + } + catch + { + return 0; + } + } + + private static string GetCoinbaseAPIData(string URL) + { + string ResponseFromServer; + try + { + HttpWebRequest WR = (HttpWebRequest)WebRequest.Create(URL); + WR.Timeout = 5000; + WebResponse Response = WR.GetResponse(); + Stream SS = Response.GetResponseStream(); + SS.ReadTimeout = 5000; + StreamReader Reader = new StreamReader(SS); + ResponseFromServer = Reader.ReadToEnd(); + if (ResponseFromServer.Length == 0 || ResponseFromServer[0] != '{') + throw new Exception("Not JSON!"); + Reader.Close(); + Response.Close(); + } + catch + { + return null; + } + + return ResponseFromServer; + } + } +} diff --git a/NiceHashMiner/Config.cs b/NiceHashMiner/Config.cs index b04558a..68c6fd5 100644 --- a/NiceHashMiner/Config.cs +++ b/NiceHashMiner/Config.cs @@ -42,6 +42,7 @@ public class Config public string WorkerName; public int Location; public int LessThreads; + public int ForceCPUExtension; // 0 - automatic, 1 - SSE2, 2 - AVX, 3 - AVX2 public int SwitchMinSecondsFixed; public int SwitchMinSecondsDynamic; public int MinerAPIQueryInterval; diff --git a/NiceHashMiner/Form1.Designer.cs b/NiceHashMiner/Form1.Designer.cs index 3d76488..025cd27 100644 --- a/NiceHashMiner/Form1.Designer.cs +++ b/NiceHashMiner/Form1.Designer.cs @@ -37,6 +37,8 @@ private void InitializeComponent() this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel9 = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabel4 = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabel5 = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabel6 = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabel7 = new System.Windows.Forms.ToolStripStatusLabel(); @@ -62,6 +64,9 @@ private void InitializeComponent() this.label14 = new System.Windows.Forms.Label(); this.label15 = new System.Windows.Forms.Label(); this.button3 = new System.Windows.Forms.Button(); + this.label16 = new System.Windows.Forms.Label(); + this.label17 = new System.Windows.Forms.Label(); + this.label18 = new System.Windows.Forms.Label(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -119,6 +124,8 @@ private void InitializeComponent() this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripStatusLabel9, this.toolStripStatusLabel4, + this.toolStripStatusLabel1, + this.toolStripStatusLabel2, this.toolStripStatusLabel5, this.toolStripStatusLabel6, this.toolStripStatusLabel7}); @@ -141,11 +148,24 @@ private void InitializeComponent() this.toolStripStatusLabel4.Size = new System.Drawing.Size(73, 17); this.toolStripStatusLabel4.Text = "0.00000000"; // + // toolStripStatusLabel1 + // + this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; + this.toolStripStatusLabel1.Size = new System.Drawing.Size(63, 17); + this.toolStripStatusLabel1.Text = "BTC/Day "; + // + // toolStripStatusLabel2 + // + this.toolStripStatusLabel2.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold); + this.toolStripStatusLabel2.Name = "toolStripStatusLabel2"; + this.toolStripStatusLabel2.Size = new System.Drawing.Size(31, 17); + this.toolStripStatusLabel2.Text = "0.00"; + // // toolStripStatusLabel5 // this.toolStripStatusLabel5.Name = "toolStripStatusLabel5"; - this.toolStripStatusLabel5.Size = new System.Drawing.Size(113, 17); - this.toolStripStatusLabel5.Text = "BTC/Day Balance:"; + this.toolStripStatusLabel5.Size = new System.Drawing.Size(97, 17); + this.toolStripStatusLabel5.Text = "$/Day Balance:"; // // toolStripStatusLabel6 // @@ -301,7 +321,7 @@ private void InitializeComponent() // label10 // this.label10.AutoSize = true; - this.label10.Location = new System.Drawing.Point(287, 199); + this.label10.Location = new System.Drawing.Point(300, 199); this.label10.Name = "label10"; this.label10.Size = new System.Drawing.Size(33, 13); this.label10.TabIndex = 20; @@ -311,7 +331,7 @@ private void InitializeComponent() // this.label11.AutoSize = true; this.label11.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label11.Location = new System.Drawing.Point(326, 199); + this.label11.Location = new System.Drawing.Point(330, 199); this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(112, 13); this.label11.TabIndex = 21; @@ -321,7 +341,7 @@ private void InitializeComponent() // this.label12.AutoSize = true; this.label12.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label12.Location = new System.Drawing.Point(326, 212); + this.label12.Location = new System.Drawing.Point(330, 212); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(112, 13); this.label12.TabIndex = 23; @@ -330,7 +350,7 @@ private void InitializeComponent() // label13 // this.label13.AutoSize = true; - this.label13.Location = new System.Drawing.Point(287, 212); + this.label13.Location = new System.Drawing.Point(300, 212); this.label13.Name = "label13"; this.label13.Size = new System.Drawing.Size(33, 13); this.label13.TabIndex = 22; @@ -340,7 +360,7 @@ private void InitializeComponent() // this.label14.AutoSize = true; this.label14.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); - this.label14.Location = new System.Drawing.Point(326, 225); + this.label14.Location = new System.Drawing.Point(330, 225); this.label14.Name = "label14"; this.label14.Size = new System.Drawing.Size(112, 13); this.label14.TabIndex = 25; @@ -349,7 +369,7 @@ private void InitializeComponent() // label15 // this.label15.AutoSize = true; - this.label15.Location = new System.Drawing.Point(287, 225); + this.label15.Location = new System.Drawing.Point(300, 225); this.label15.Name = "label15"; this.label15.Size = new System.Drawing.Size(33, 13); this.label15.TabIndex = 24; @@ -365,11 +385,41 @@ private void InitializeComponent() this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // + // label16 + // + this.label16.AutoSize = true; + this.label16.Location = new System.Drawing.Point(448, 199); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(61, 13); + this.label16.TabIndex = 27; + this.label16.Text = "0.00 $/Day"; + // + // label17 + // + this.label17.AutoSize = true; + this.label17.Location = new System.Drawing.Point(448, 212); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(61, 13); + this.label17.TabIndex = 28; + this.label17.Text = "0.00 $/Day"; + // + // label18 + // + this.label18.AutoSize = true; + this.label18.Location = new System.Drawing.Point(448, 225); + this.label18.Name = "label18"; + this.label18.Size = new System.Drawing.Size(61, 13); + this.label18.TabIndex = 29; + this.label18.Text = "0.00 $/Day"; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(531, 265); + this.Controls.Add(this.label18); + this.Controls.Add(this.label17); + this.Controls.Add(this.label16); this.Controls.Add(this.button3); this.Controls.Add(this.label14); this.Controls.Add(this.label15); @@ -446,6 +496,11 @@ private void InitializeComponent() private System.Windows.Forms.Label label14; private System.Windows.Forms.Label label15; private System.Windows.Forms.Button button3; + private System.Windows.Forms.Label label16; + private System.Windows.Forms.Label label17; + private System.Windows.Forms.Label label18; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2; } } diff --git a/NiceHashMiner/Form1.cs b/NiceHashMiner/Form1.cs index e9a83bc..d3db30b 100644 --- a/NiceHashMiner/Form1.cs +++ b/NiceHashMiner/Form1.cs @@ -6,6 +6,7 @@ using System.Text; using System.Windows.Forms; using System.Diagnostics; +using System.Globalization; namespace NiceHashMiner { @@ -22,12 +23,15 @@ public partial class Form1 : Form private Timer SMACheck; private Timer BalanceCheck; private Timer SMAMinerCheck; + private Timer BitcoinExchangeCheck; private Timer StartupTimer; private Form3 LoadingScreen; private int LoadCounter = 0; private Random R; + private double BitcoinRate; + public Form1() { @@ -159,6 +163,12 @@ void StartupTimer_Tick(object sender, EventArgs e) BalanceCheck.Interval = 61 * 1000; // every 61 seconds BalanceCheck.Start(); BalanceCheck_Tick(null, null); + + BitcoinExchangeCheck = new Timer(); + BitcoinExchangeCheck.Tick += BitcoinExchangeCheck_Tick; + BitcoinExchangeCheck.Interval = 1000 * 3601; // every 1 hour and 1 second + BitcoinExchangeCheck.Start(); + BitcoinExchangeCheck_Tick(null, null); } @@ -178,7 +188,7 @@ private void Form1_Shown(object sender, EventArgs e) private void IncreaseLoadCounter() { LoadCounter++; - if (LoadCounter >= 3) + if (LoadCounter >= 4) { if (LoadingScreen != null) { @@ -271,24 +281,27 @@ private void MinerStatsCheck_Tick(object sender, EventArgs e) private void SetCPUStats(string aname, double speed, double paying) { - label5.Text = (speed * 0.001).ToString("F2") + " kH/s " + aname; - label11.Text = paying.ToString("F8") + " BTC/Day"; + label5.Text = (speed * 0.001).ToString("F2", CultureInfo.InvariantCulture) + " kH/s " + aname; + label11.Text = paying.ToString("F8", CultureInfo.InvariantCulture) + " BTC/Day"; + label16.Text = (paying * BitcoinRate).ToString("F2", CultureInfo.InvariantCulture) + " $/Day"; UpdateGlobalRate(); } private void SetNVIDIAtpStats(string aname, double speed, double paying) { - label8.Text = (speed * 0.000001).ToString("F2") + " MH/s " + aname; - label14.Text = paying.ToString("F8") + " BTC/Day"; + label8.Text = (speed * 0.000001).ToString("F2", CultureInfo.InvariantCulture) + " MH/s " + aname; + label14.Text = paying.ToString("F8", CultureInfo.InvariantCulture) + " BTC/Day"; + label18.Text = (paying * BitcoinRate).ToString("F2", CultureInfo.InvariantCulture) + " $/Day"; UpdateGlobalRate(); } private void SetNVIDIAspStats(string aname, double speed, double paying) { - label6.Text = (speed * 0.000001).ToString("F2") + " MH/s " + aname; - label12.Text = paying.ToString("F8") + " BTC/Day"; + label6.Text = (speed * 0.000001).ToString("F2", CultureInfo.InvariantCulture) + " MH/s " + aname; + label12.Text = paying.ToString("F8", CultureInfo.InvariantCulture) + " BTC/Day"; + label17.Text = (paying * BitcoinRate).ToString("F2", CultureInfo.InvariantCulture) + " $/Day"; UpdateGlobalRate(); } @@ -298,16 +311,27 @@ private void UpdateGlobalRate() double TotalRate = 0; foreach (Miner m in Miners) TotalRate += m.CurrentRate; - toolStripStatusLabel4.Text = (TotalRate).ToString("F8"); + toolStripStatusLabel4.Text = (TotalRate).ToString("F8", CultureInfo.InvariantCulture); + toolStripStatusLabel2.Text = (TotalRate * BitcoinRate).ToString("F2", CultureInfo.InvariantCulture); } void BalanceCheck_Tick(object sender, EventArgs e) { - if (!VerifyMiningAddress()) return; - Helpers.ConsolePrint("NICEHASH: balance get"); - double Balance = NiceHashStats.GetBalance(textBox1.Text.Trim()); - if (Balance > 0) toolStripStatusLabel6.Text = Balance.ToString("F8"); + if (VerifyMiningAddress()) + { + Helpers.ConsolePrint("NICEHASH: balance get"); + double Balance = NiceHashStats.GetBalance(textBox1.Text.Trim()); + if (Balance > 0) toolStripStatusLabel6.Text = Balance.ToString("F8", CultureInfo.InvariantCulture); + } + IncreaseLoadCounter(); + } + + + void BitcoinExchangeCheck_Tick(object sender, EventArgs e) + { + Helpers.ConsolePrint("COINBASE: bitcoin rate get"); + BitcoinRate = Bitcoin.GetUSDExchangeRate(); IncreaseLoadCounter(); } @@ -411,6 +435,7 @@ private void button2_Click(object sender, EventArgs e) { m.Stop(); m.CurrentAlgo = -1; + m.CurrentRate = 0; } SetCPUStats("", 0, 0); @@ -424,6 +449,8 @@ private void button2_Click(object sender, EventArgs e) button1.Enabled = true; listView1.Enabled = true; button2.Enabled = false; + + UpdateGlobalRate(); } diff --git a/NiceHashMiner/Miner.cs b/NiceHashMiner/Miner.cs index c109fff..1fc205f 100644 --- a/NiceHashMiner/Miner.cs +++ b/NiceHashMiner/Miner.cs @@ -276,7 +276,7 @@ virtual public void Restart() virtual public string PrintSpeed(double spd) { // print in MH/s - return (spd * 0.000001).ToString("F2") + " MH/s"; + return (spd * 0.000001).ToString("F3", CultureInfo.InvariantCulture) + " MH/s"; } diff --git a/NiceHashMiner/NiceHashMiner.csproj b/NiceHashMiner/NiceHashMiner.csproj index c59408c..e768723 100644 --- a/NiceHashMiner/NiceHashMiner.csproj +++ b/NiceHashMiner/NiceHashMiner.csproj @@ -65,6 +65,7 @@ + diff --git a/NiceHashMiner/Properties/AssemblyInfo.cs b/NiceHashMiner/Properties/AssemblyInfo.cs index 99b5de7..85d3576 100644 --- a/NiceHashMiner/Properties/AssemblyInfo.cs +++ b/NiceHashMiner/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.0.1")] -[assembly: AssemblyFileVersion("1.1.0.1")] +[assembly: AssemblyVersion("1.1.0.2")] +[assembly: AssemblyFileVersion("1.1.0.2")] diff --git a/NiceHashMiner/cpuminer.cs b/NiceHashMiner/cpuminer.cs index 643525e..46408e0 100644 --- a/NiceHashMiner/cpuminer.cs +++ b/NiceHashMiner/cpuminer.cs @@ -25,22 +25,40 @@ public cpuminer(int id, int threads, ulong affinity) new Algorithm(15, "scryptjanenf16", "scryptjane:16") }; - // detect CPU capabilities - if (CPUID.SupportsAVX2() == 0) + if (Config.ConfigData.ForceCPUExtension > 0) { - if (CPUID.SupportsAVX() == 0) + if (Config.ConfigData.ForceCPUExtension == 1) { - if (CPUID.SupportsSSE2() == 0) - return; - Path = "bin\\cpuminer_x64_SSE2.exe"; } - else + else if (Config.ConfigData.ForceCPUExtension == 2) + { Path = "bin\\cpuminer_x64_AVX.exe"; + } + else + { + Path = "bin\\cpuminer_x64_AVX2.exe"; + } } else { - Path = "bin\\cpuminer_x64_AVX2.exe"; + // detect CPU capabilities + if (CPUID.SupportsAVX2() == 0) + { + if (CPUID.SupportsAVX() == 0) + { + if (CPUID.SupportsSSE2() == 0) + return; + + Path = "bin\\cpuminer_x64_SSE2.exe"; + } + else + Path = "bin\\cpuminer_x64_AVX.exe"; + } + else + { + Path = "bin\\cpuminer_x64_AVX2.exe"; + } } CDevs.Add(new ComputeDevice(0, MinerDeviceName, CPUID.GetCPUName())); @@ -50,7 +68,7 @@ public cpuminer(int id, int threads, ulong affinity) public override string PrintSpeed(double spd) { // print in kH/s - return (spd * 0.001).ToString("F2") + " kH/s"; + return (spd * 0.001).ToString("F3", CultureInfo.InvariantCulture) + " kH/s"; } diff --git a/README.md b/README.md index f5bed60..83fa314 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Parameter | Range | Description -----------------|----------|------------------- DebugConsole | true or false | When set to true, it displays debug console. LessThreads | 0 .. 64 | Reduce number of threads used on each CPU by LessThreads. +ForceCPUExtension | 0, 1, 2 or 3 | Force certain CPU extension miner. 0 is automatic, 1 for SSE2, 2 for AVX and 3 for AVX2. SwitchMinSecondsFixed | number | Fixed part of minimal time (in seconds) before miner switches algorithm. Total time is SwitchMinSecondsFixed + SwitchMinSecondsDynamic. SwitchMinSecondsDynamic | number | Random part of minimal time (in seconds) before miner switches algorithm. Total time is SwitchMinSecondsFixed + SwitchMinSecondsDynamic. Random part is used to prevent all world-wide NiceHash Miner users to have the exact same switching pattern. Groups\ExtraLaunchParameters | text | Additional launch parameters when launching miner.