From 530bc06a9a1404e197a3879b7b31bd9e643c97fd Mon Sep 17 00:00:00 2001 From: Scott Alfter Date: Thu, 30 May 2013 15:19:28 -0700 Subject: [PATCH] more refactoring, and the start of a CLI app --- CoinProfitability.sln | 9 +++ CoinProfitability/Form1.cs | 27 +++++--- .../CoinProfitabilityLibrary.csproj | 5 +- CoinProfitabilityLibrary/Profitability.cs | 27 ++++++++ profit/App.config | 6 ++ profit/Program.cs | 64 +++++++++++++++++++ profit/Properties/AssemblyInfo.cs | 36 +++++++++++ profit/profit.csproj | 60 +++++++++++++++++ 8 files changed, 222 insertions(+), 12 deletions(-) create mode 100644 CoinProfitabilityLibrary/Profitability.cs create mode 100644 profit/App.config create mode 100644 profit/Program.cs create mode 100644 profit/Properties/AssemblyInfo.cs create mode 100644 profit/profit.csproj diff --git a/CoinProfitability.sln b/CoinProfitability.sln index 3b7bf65..76fec02 100644 --- a/CoinProfitability.sln +++ b/CoinProfitability.sln @@ -8,6 +8,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoinProfitability", "CoinPr EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoinProfitabilityLibrary", "CoinProfitabilityLibrary\CoinProfitabilityLibrary.csproj", "{F496F99C-A09D-40A0-BC87-5662893FCBB3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "profit", "profit\profit.csproj", "{9333557A-9A72-4DD8-8A15-25AE3B273800}" + ProjectSection(ProjectDependencies) = postProject + {F496F99C-A09D-40A0-BC87-5662893FCBB3} = {F496F99C-A09D-40A0-BC87-5662893FCBB3} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -22,6 +27,10 @@ Global {F496F99C-A09D-40A0-BC87-5662893FCBB3}.Debug|Any CPU.Build.0 = Debug|Any CPU {F496F99C-A09D-40A0-BC87-5662893FCBB3}.Release|Any CPU.ActiveCfg = Release|Any CPU {F496F99C-A09D-40A0-BC87-5662893FCBB3}.Release|Any CPU.Build.0 = Release|Any CPU + {9333557A-9A72-4DD8-8A15-25AE3B273800}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9333557A-9A72-4DD8-8A15-25AE3B273800}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9333557A-9A72-4DD8-8A15-25AE3B273800}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9333557A-9A72-4DD8-8A15-25AE3B273800}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CoinProfitability/Form1.cs b/CoinProfitability/Form1.cs index ec06f26..87ac9a0 100644 --- a/CoinProfitability/Form1.cs +++ b/CoinProfitability/Form1.cs @@ -80,20 +80,31 @@ namespace CoinProfitability private void OnChanged() { + Profitability p = new Profitability(); try { - BigInteger interval = new BigInteger(Convert.ToInt64(((Item)(cbInterval.SelectedItem)).Value)); - BigInteger hashrate = new BigInteger(Convert.ToDecimal(tbHashrate.Text)) * Convert.ToInt64(((Item)(cbHashrateUnit.SelectedItem)).Value); - BigInteger reward = new BigInteger(Convert.ToDecimal(tbReward.Text)) * 100000000; - decimal difficulty = Convert.ToDecimal(tbDifficulty.Text); + //BigInteger interval = new BigInteger(Convert.ToInt64(((Item)(cbInterval.SelectedItem)).Value)); + //BigInteger hashrate = new BigInteger(Convert.ToDecimal(tbHashrate.Text)) * Convert.ToInt64(((Item)(cbHashrateUnit.SelectedItem)).Value); + //BigInteger reward = new BigInteger(Convert.ToDecimal(tbReward.Text)) * 100000000; + //decimal difficulty = Convert.ToDecimal(tbDifficulty.Text); - BigInteger target = ((new BigInteger(65535) << 208) * 100000000000) / new BigInteger(difficulty * 100000000000); - BigInteger revenue = interval * target * hashrate * reward / (new BigInteger(1) << 256); + //BigInteger target = ((new BigInteger(65535) << 208) * 100000000000) / new BigInteger(difficulty * 100000000000); + //BigInteger revenue = interval * target * hashrate * reward / (new BigInteger(1) << 256); - tbIncome.Text = ((decimal)revenue / (decimal)100000000).ToString("F8"); + //tbIncome.Text = ((decimal)revenue / (decimal)100000000).ToString("F8"); + + tbIncome.Text = p.ProfitOnInterval(Convert.ToInt64(((Item)(cbInterval.SelectedItem)).Value), + Convert.ToDecimal(tbHashrate.Text) * Convert.ToInt64(((Item)(cbHashrateUnit.SelectedItem)).Value), + Convert.ToDecimal(tbReward.Text), + Convert.ToDecimal(tbDifficulty.Text)).ToString("F8"); if (tbExchangeRate.Text != "") - tbIncomeBTC.Text = (Convert.ToDecimal(tbExchangeRate.Text) * (decimal)revenue / (decimal)100000000).ToString("F8"); + //tbIncomeBTC.Text = (Convert.ToDecimal(tbExchangeRate.Text) * (decimal)revenue / (decimal)100000000).ToString("F8"); + tbIncomeBTC.Text = p.ProfitOnIntervalBTC(Convert.ToInt64(((Item)(cbInterval.SelectedItem)).Value), + Convert.ToDecimal(tbHashrate.Text) * Convert.ToInt64(((Item)(cbHashrateUnit.SelectedItem)).Value), + Convert.ToDecimal(tbReward.Text), + Convert.ToDecimal(tbDifficulty.Text), + Convert.ToDecimal(tbExchangeRate.Text)).ToString("F8"); else tbIncomeBTC.Text = "---"; } diff --git a/CoinProfitabilityLibrary/CoinProfitabilityLibrary.csproj b/CoinProfitabilityLibrary/CoinProfitabilityLibrary.csproj index 38dfbd1..c978a81 100644 --- a/CoinProfitabilityLibrary/CoinProfitabilityLibrary.csproj +++ b/CoinProfitabilityLibrary/CoinProfitabilityLibrary.csproj @@ -35,14 +35,11 @@ - - - - + diff --git a/CoinProfitabilityLibrary/Profitability.cs b/CoinProfitabilityLibrary/Profitability.cs new file mode 100644 index 0000000..365d3bb --- /dev/null +++ b/CoinProfitabilityLibrary/Profitability.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Numerics; + +namespace ScottAlfter.CoinProfitabilityLibrary +{ + public class Profitability + { + public decimal ProfitOnInterval(long lInterval, decimal dHashRate, decimal dReward, decimal dDifficulty) + { + BigInteger interval = new BigInteger(lInterval); + BigInteger hashrate = new BigInteger(dHashRate); + BigInteger reward = new BigInteger(dReward) * 100000000; + decimal difficulty = dDifficulty; + BigInteger target = ((new BigInteger(65535) << 208) * 100000000000) / new BigInteger(difficulty * 100000000000); + BigInteger revenue = interval * target * hashrate * reward / (new BigInteger(1) << 256); + return (decimal)revenue / (decimal)100000000; + } + + public decimal ProfitOnIntervalBTC(long lInterval, decimal dHashRate, decimal dReward, decimal dDifficulty, decimal dExchangeRate) + { + return ProfitOnInterval(lInterval, dHashRate, dReward, dDifficulty) * dExchangeRate; + } + } +} diff --git a/profit/App.config b/profit/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/profit/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/profit/Program.cs b/profit/Program.cs new file mode 100644 index 0000000..4af3ddf --- /dev/null +++ b/profit/Program.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ScottAlfter.CoinProfitabilityLibrary; +using Gnu.Getopt; + +namespace profit +{ + class Program + { + static void Help() + { + Console.WriteLine("Usage: profit [options]"); + Console.WriteLine(""); + Console.WriteLine("Options:"); + Console.WriteLine(" -h|--help this message"); + Console.WriteLine(" -l|--list list coins configured in registry"); + Console.WriteLine(" -c|--coin select coin to look up"); + Console.WriteLine(" -b|--bitcoin expected income in BTC"); + Console.WriteLine(" -r|--hashrate override hashrate (provide in H/s)"); + } + + static void Main(string[] args) + { + RegistrySettings rs = new RegistrySettings(); + Getopt go = new Getopt("profit", args, "hlc:br:", + new LongOpt[] + { + new LongOpt("help", Argument.No, null, 'h'), + new LongOpt("list", Argument.No, null, 'l'), + new LongOpt("coin", Argument.Required, null, 'c'), + new LongOpt("bitcoin", Argument.No, null, 'b'), + new LongOpt("hashrate", Argument.Required, null, 'r') + }); + int opt=-1; + bool bIncomeInBTC = false; + string szSelectedCoin = "Bitcoin"; + + while ((opt=go.getopt())!=-1) + switch (opt) + { + case 'h': + Help(); + return; + case 'l': + foreach (string name in rs.GetCoinTypes()) + Console.WriteLine(name); + return; + case 'c': + szSelectedCoin = go.Optarg; + break; + case 'b': + bIncomeInBTC = true; + break; + default: + Help(); + return; + } + + } + } +} diff --git a/profit/Properties/AssemblyInfo.cs b/profit/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..81ea7c2 --- /dev/null +++ b/profit/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("profit")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("profit")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("780b6e16-e841-4b79-afa1-c59f5ebba54d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// 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.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/profit/profit.csproj b/profit/profit.csproj new file mode 100644 index 0000000..7d8b13d --- /dev/null +++ b/profit/profit.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {9333557A-9A72-4DD8-8A15-25AE3B273800} + Exe + Properties + profit + profit + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\CoinProfitabilityLibrary\bin\Release\CoinProfitabilityLibrary.dll + + + ..\..\..\Visual Studio 2008\Projects\Gnu.Getopt\bin\Release\Gnu.Getopt.dll + + + + + + + + + + + + + + + \ No newline at end of file