Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Fixes and improvements
Browse files Browse the repository at this point in the history
- Added more config options
- Added $/Day income calculation
- Bug fixes
  • Loading branch information
nicehashdev committed Oct 22, 2015
1 parent 2a34342 commit b9aa683
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 32 deletions.
61 changes: 61 additions & 0 deletions NiceHashMiner/Bitcoin.cs
Original file line number Diff line number Diff line change
@@ -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<CoinbaseResponse>(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;
}
}
}
1 change: 1 addition & 0 deletions NiceHashMiner/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
71 changes: 63 additions & 8 deletions NiceHashMiner/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 39 additions & 12 deletions NiceHashMiner/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Globalization;

namespace NiceHashMiner
{
Expand All @@ -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()
{
Expand Down Expand Up @@ -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);
}


Expand All @@ -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)
{
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -411,6 +435,7 @@ private void button2_Click(object sender, EventArgs e)
{
m.Stop();
m.CurrentAlgo = -1;
m.CurrentRate = 0;
}

SetCPUStats("", 0, 0);
Expand All @@ -424,6 +449,8 @@ private void button2_Click(object sender, EventArgs e)
button1.Enabled = true;
listView1.Enabled = true;
button2.Enabled = false;

UpdateGlobalRate();
}


Expand Down
2 changes: 1 addition & 1 deletion NiceHashMiner/Miner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}


Expand Down
1 change: 1 addition & 0 deletions NiceHashMiner/NiceHashMiner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BitcoinAddress.cs" />
<Compile Include="Bitcoin.cs" />
<Compile Include="ccminer_sp.cs" />
<Compile Include="ccminer.cs" />
<Compile Include="ccminer_tpruvot.cs" />
Expand Down
4 changes: 2 additions & 2 deletions NiceHashMiner/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Loading

0 comments on commit b9aa683

Please sign in to comment.