more refactoring, and the start of a CLI app
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 = "---";
|
||||
}
|
||||
|
||||
@@ -35,14 +35,11 @@
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CoinInformation.cs" />
|
||||
<Compile Include="Profitability.cs" />
|
||||
<Compile Include="ExchangeInformation.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RegistrySettings.cs" />
|
||||
|
||||
27
CoinProfitabilityLibrary/Profitability.cs
Normal file
27
CoinProfitabilityLibrary/Profitability.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
6
profit/App.config
Normal file
6
profit/App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
||||
64
profit/Program.cs
Normal file
64
profit/Program.cs
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
36
profit/Properties/AssemblyInfo.cs
Normal file
36
profit/Properties/AssemblyInfo.cs
Normal file
@@ -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")]
|
||||
60
profit/profit.csproj
Normal file
60
profit/profit.csproj
Normal file
@@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{9333557A-9A72-4DD8-8A15-25AE3B273800}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>profit</RootNamespace>
|
||||
<AssemblyName>profit</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="CoinProfitabilityLibrary">
|
||||
<HintPath>..\CoinProfitabilityLibrary\bin\Release\CoinProfitabilityLibrary.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Gnu.Getopt">
|
||||
<HintPath>..\..\..\Visual Studio 2008\Projects\Gnu.Getopt\bin\Release\Gnu.Getopt.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
Reference in New Issue
Block a user